前端代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script th:src="@{/js/jquery.js}"></script>
<script type="text/javascript">
</script>
<title></title>
<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet" />
</head>
<body>
<form name="form1" method="post" th:action="@{/manage/toAddAdminPage}" id="form1">
<div style="margin-bottom:10px; padding:8px 0 8px 15px; background-color:#F5F5F5">
<a th:href="@{/manage/adminDefault}">桌面</a> >>
<a th:href="@{/manage/adminManage}">管理员信息管理</a> >>
<a th:href="@{/manage/toAddAdminPage}" style="color:red;">添加管理员</a></div>
<div style="width:800px; margin:0 auto;">
<div th:if="${checkPwd} != null or ${checkPwd} != true">
<th:block th:if="${checkPwd} == false">
<script type="text/javascript" th:if="${checkPwd} == false">
alert("密码错误!");
</script>
</th:block>
<div id="pl_CheckPwd">
<table style="width:350px; margin:25px auto; text-align:left">
<tr style="height:35px"><td colspan="2"> 验证密码:</td></tr><tr><td>
<input name="tb_CheckPwd" type="password" id="tb_CheckPwd" class="form-control" style="width:200px;" /></td><td>
<input type="hidden" name="_method" value="put">
<input type="submit" name="bt_confirm" value="确 定" id="bt_confirm" class="btn btn-primary" />
</td>
</tr>
</table>
</div>
</div>
<div id="pl_AdmInfo" th:if="${checkPwd}">
<table id="StuInfo" class="table table-bordered table-hover">
<caption><center><h3><b>添加管理员</b></h3></center></caption>
<tbody>
<tr>
<td style="text-align:right;">手机号:</td>
<td ><input name="adminTel" type="text" id="tb_Phone" th:value="${newAdmin.adminPhone}" class="form-control" required="" /></td>
<td style="width:110px; text-align:right;">密码:</td>
<td><input name="adminPwd" type="password" id="tb_Pwd" class="form-control" required="" /></td>
</tr>
<tr>
<td style="width:120px;text-align:right;">姓名:</td>
<td>
<input name="adminName" type="text" id="tb_name" th:value="${newAdmin.adminName}" class="form-control" required="" /></td>
<td style="width:120px;text-align:right;">邮箱:</td>
<td>
<input name="email" type="text" id="tb_Email" th:value="${newAdmin.adminEmail}" class="form-control" required="" />
</td>
</tr>
<tr>
<td></td>
<td colspan="3" >
<input type="submit" name="bt_Save" value="保 存" id="bt_Save" class="btn btn-primary" />
<span style="color: red;font-size: 22px;">
<th:block th:if="${isAdminExists}">账号已存在!</th:block>
<th:block th:if="${errorInfo}.adminTel">手机号输入格式错误;</th:block>
<th:block th:if="${errorInfo}.adminPwd">密码长度在6到16之间;</th:block>
<th:block th:if="${errorInfo}.email">电子邮件地址不合法;</th:block>
 
</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</form>
</body>
</html>
后端代码:
@PutMapping(value = "/toAddAdminPage")
public String toAddAdminPagePut(HttpServletRequest req){
String pwd = req.getParameter("tb_CheckPwd");
Admininfo admin = (Admininfo) req.getSession().getAttribute("loginAdmin");
if(admin.getAdminPassword().equals(pwd)){
req.setAttribute("checkPwd",true);
}else{
req.setAttribute("checkPwd",false);
}
return "admin/addAdmin";
}
在网上找了好多,springboot配置文件也配置了
spring: mvc: hiddenmethod: filter: enabled: true
还是没用,一直走的是post方法,求大佬看看帮忙解决一下,感谢!!!
<form name="form1" method="post" th:action="@{/manage/toAddAdminPage}" id="form1"> 这里不是写了你要走的请求是post。
method="post" 改成 method="put"