Simple implementation of modified query
UserController
@RequestMapping(\"/findById.do\")public String findById(int id, Model model){User user = userService.findById(id);model.addAttribute(\"user\",user);return \"../modify\";}@RequestMapping(\"/update.do\")public String update(User user){boolean del = userService.update(user);if(del){return \"redirect:findAll.do\";}else {return \"../failure\";}}
UserService
User findById(Integer id);boolean update(User user);List<User> searchByName(String name);
UserServiceImpl
@Overridepublic User findById(Integer id){User user = userDao.findUserById(id);return user;}@Overridepublic boolean update(User user){int upd = userDao.update(user);if(upd > 0){return true;}else return false;}@Overridepublic List<User> searchByName(String name){return userDao.searchByName(name);}
UserDao
int update(User user);User findUserById(Integer id);List<User> searchByName(String name);
UserMapper
<select id=\"findUserById\" parameterType=\"Integer\" resultType=\"User\">select * from user where id=#{id}</select><update id=\"update\" parameterType=\"User\">update user set name=#{name},password=#{password} where id=#{id}</update><select id=\"searchByName\" parameterType=\"String\" resultType=\"User\">select * from user where name like concat(\'%\',#{name},\'%\')</select>
modify.jsp
<%@ page contentType=\"text/html;charset=UTF-8\" language=\"java\" %><html><head><title>修改</title></head><body><div><form action=\"/user/update.do\"><input name=\"id\" value=\"${user.id}\" type=\"hidden\"><div><label for=\"name\">用户名:</label><input name=\"name\" type=\"text\" id=\"name\" value=\"${user.name}\"></div><div><label for=\"password\">密码</label><input name=\"password\" type=\"text\" id=\"password\" value=\"${user.password}\"></div><div><input type=\"submit\" value=\"提交\"></div><a href=\"javasceipt:window.history.go(-1)\">返回</a></form></div></body></html>
main.jsp
<%@ page contentType=\"text/html;charset=UTF-8\" language=\"java\" %><html><head><title>列表</title></head><body><div><form action=\"/user/findAll.do\"><input id=\"name\" type=\"search\" name=\"name\" value=\"${name}\"><button onclick=\"form.submit()\">搜索</button></form><TABLE><THEAD><TR><th>ID</th><th>用户名</th><th>密码</th><th>操作</th></TR></THEAD><tbody><c:forEach items=\"${userList}\" var=\"user\"><tr><td>${user.id}</td><td>${user.name}</td><td>${user.password}</td><td><a href=\"${pageContext.request.contextPath}/user/delete.do?id=${user.id}\">删除</a><a href=\"${pageContext.request.contextPath}/user/findById.do?id=${user.id}\">修改</a></td></tr></c:forEach></tbody></TABLE></div></body></html>