1、在login.html
用户列表
<div th:each="userInfo,status:${list}">
<table><tr>
<td><a th:href="@{delete(userId=${userInfo.userId})}"><span th:text="${userInfo.userId}"></span></a></td>
<td><a th:href="@{change(userId=${userInfo.userId},userName=${userInfo.userName})}"><span th:text="${userInfo.userName}"></span></a></td></tr></table></div>
关键代码:<a th:href="@{change(userId=${userInfo.userId},userName=${userInfo.userName})}">
1、在xiugai.html修改页面
<div><span th:text="${message}"></span></div>
<form action="update" th:object="${userBean}" method="post">
<table>
<tr><td><caption>修改界面</caption></td></tr>
<tr><td>ID:<input name="userId" type="text" th:value="${userBean.userId}"/></td></tr>
<tr> <td>用户名:<input name="userName" type="text" th:value="${userBean.userName}"/></td> </tr>
<tr><td>密码:<input name="passWord" type="password"/></td></tr>
<tr><td>确认密码:<input name="passWordconfim" type="password" /></td</tr>
<tr><td> <button type="sumbit" name="xiugai">修改</button> </td> </tr></table>
</form>
关键代码:<form action="update" th:object="${userBean}" method="post">
<td>ID:<input name="userId" type="text" th:value="${userBean.userId}"/></td>
<td>用户名:<input name="userName" type="text" th:value="${userBean.userName}"/></td>
2、在Hellowordcontroller.java
@RequestMapping(value = "/change", method = RequestMethod.GET)
public String change(UserBean userBean, Model model) {
return "xiugai";}
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String updateLogin(UserBean userBean, Model model) {
int update = helloWorldService.update(userBean);
if(update==1)
{ List<UserBean> refresh=helloWorldService.checkUser(userBean);
model.addAttribute("list",refresh);
return "login"; }
else{ model.addAttribute("message","更新失败");
model.addAttribute("userBean",userBean);
return "xiugai"; } }}
关键代码: int update = helloWorldService.update(userBean);
3、在hellowordservice.java
public int update(UserBean frm){
return updateDao.execute("User.userupdate", frm);
}
4、在usersqlmap.xml
<update id="userupdate" parameterClass="cn.training.bean.UserBean">
UPDATE
user SET username=#userName#,password=#passWord#
WHERE userid = #userId#</update>