前端链接
<a href="${pageContext.request.contextPath}/user/toUpdate.do?id=${user.id}" class="btn bg-olive btn-xs">更新</a>数据库语句(xml配置文件) UserMapper.xml
<select id="selectById" parameterType="int" resultType="user"> select * from tb_user where id = #{id} </select> <update id="updateAll" parameterType="user"> update tb_user set username=#{username},password=#{password} where id=#{id} </update>UserController类
@RequestMapping("/toUpdate.do") public ModelAndView toUpdate(int id){ User user = userService.selectUserById(id); ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("user-update"); modelAndView.addObject("user",user); return modelAndView; } @RequestMapping("/updateAll.do") public String updateAll(User user){ userService.updateAll(user); return "redirect: findAll.do"; }UserDao接口
User selectById(int id); void updateAll(User user);IUserService接口
User selectUserById(int id); void updateAll(User user);IUserService类
@Override public User selectUserById(int id) { return userDao.selectById(id); } @Override public void updateAll(User user) { userDao.updateAll(user); }