【发布时间】:2018-07-26 08:38:31
【问题描述】:
我正在尝试安装一个简单的开始菜单,但当我按下提交按钮时,POST 方法中出现错误。
我的控制器使用 html 中的提交调用的 post 方法,其值为“login”
@Controller
@RequestMapping("usuario")
public class UsuarioControlador {
@Autowired
private UsuarioServicio usuarios;
@RequestMapping(method=RequestMethod.GET )
public String index(ModelMap modelMap){
modelMap.put("usuario",new Usuario());
return "usuario/index";
}
//@PostMapping("/login")
@RequestMapping(value="login",method=RequestMethod.POST)
public String login(@ModelAttribute("usuario")Usuario usuario,HttpSession session,ModelMap modelMap){
if(usuarios.findByUserId(usuario.getIdUsuario())!=null){
session.setAttribute("informacion", usuario.getInformacion());
return "usuario/welcome";
}else{
modelMap.put("error", "Usuario no valido");
return "usuario/index";
}
}
}
我的 index.html 与提交调用“登录”
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form th:action="@{/usuario/login}"
th:objects="${usuario}" method="post">
<table cellpading="2" cellspacing="2">
<tr>
<td>Usuario</td>
<td><input type="text" th:field="*{idUsuario}" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="login" /></td>
</tr>
</table>
<br/>
<span th:text="${error}"></span>
</form>
</body>
</html>
【问题讨论】:
-
你需要设置 content-type 并接受 headers
-
以文本而不是图像的形式提供内嵌代码。
-
这是我第一次来抱歉,我只是修改它...
-
请添加异常的堆栈跟踪
标签: spring spring-mvc spring-boot post