The Fifth------JAVA通过ssm实现简单修改更新操作

    技术2022-07-11  80

    The Fifth------JAVA通过ssm实现简单修改更新操作

    主要操作

    通过数据库语言传递接口操作前端链接代码

    前端链接

    <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); }
    Processed: 0.016, SQL: 9