【发布时间】:2020-01-03 22:35:04
【问题描述】:
我在尝试接收 form 的值时遇到问题。我将使用此值来刷新我使用该值的同一页面,例如过滤器(按城市过滤):
<form action="/todoslosusuarios" modelAttribute="TodosLosUsuarios">
<table>
<tr>
<td>Ciudad</td>
<td><input type="text" ciudad="ciudad"></input></td>
</tr>
<tr rowspan="2">
<td><input type="submit"></input></td>
</tr>
</table>
</form>
问题是它不起作用:
所以,这意味着我没有正确读取该值。
这是我的控制器代码:
@Controller
public class ExtraerTodosLosUsuariosRegistrado {
@RequestMapping(value = "/todoslosusuarios", method = RequestMethod.GET)
public String ExtraerTodosLosUsuariosRegistrados(Model model) throws ParseException {
tablausuario tu = new tablausuario();
ArrayList<usuario> user = tu.listausuarios();
Collections.sort(user, (o1, o2) -> o2.getCreatedAt().compareTo(o1.getCreatedAt())); //tabla ordenada
model.addAttribute("TodosLosUsuarios", user);
return "ExtraerTodosLosUsuariosRegistrados";
}
@RequestMapping(value = "/todoslosusuarios", method = RequestMethod.POST)
public String ciudad(Model model, @RequestBody("ciudad") String ciudad) {
tablausuariofilterbycity tufc = new tablausuariofilterbycity();
ArrayList<usuario> userbycity = tufc.listausuariosfiltradosporciudad(ciudad);
model.addAttribute("TodosLosUsuarios", userbycity);
return "ExtraerTodosLosUsuariosRegistrados";
}
}
这是我的 HTML “ExtraerTodosLosUsuariosRegistrados”
<div class="container">
<h2>Listado de usuarios </h2>
<p th:text=" ${TodosLosUsuarios.size()} "></p>
<form action="/test" modelAttribute="TodosLosUsuarios">
<table>
<tr>
<td>Ciudad</td>
<td><input type="text" ciudad="ciudad"></input></td>
</tr>
<tr rowspan="2">
<td><input type="submit"></input></td>
</tr>
</table>
</form>
<table class="table table-bordered" sortable>
<thead>
<tr>
<th>Nombre</th>
<th>Email</th>
<th>Teléfono</th>
<th>Día creado</th>
<th>Edad</th>
<th>Confirmado</th>
<th>Promocion</th>
<th>Direccion</th>
</tr>
</thead>
<tbody th:each="usuariosTotales: ${TodosLosUsuarios}" >
<tr>
<td th:text=" ${usuariosTotales.getNombre()} " ></td>
<td th:text=" ${usuariosTotales.getEmail()} " ></td>
<td th:text=" ${usuariosTotales.getPhoneNunmber()} " ></td>
<td th:text=" ${usuariosTotales.getCreatedAt()} " ></td>
<td th:text=" ${usuariosTotales.getEdad()} " ></td>
<td th:text=" ${usuariosTotales.getConfirmationCode()} " ></td>
<td th:text=" ${usuariosTotales.getPromotions()} " ></td>
<td th:text=" ${usuariosTotales.getAddress()} " ></td>
</tr>
</tbody>
</table>
</div>
谁能帮我看看我做错了什么?
【问题讨论】:
-
尝试将 ciudad="ciudad" 替换为 name="ciudad"。
标签: java html spring post controller