Mybatis-Plus指定修改欄位
阿新 • • 發佈:2018-11-29
核心程式碼 22 - 30
/** * 修改密碼(只能修改自己的密碼) * * @author zhangxuewei * @param userID * @param password * @param session * @return */ @ResponseBody @RequestMapping(value = "/updateUserPWD", method = RequestMethod.POST) public ResultCode updateUserPWD(@RequestParam(value = "password_old") String password, @RequestParam(value = "password_new") String newpassword, HttpSession session) { logger.info("updateUserPWD ..........."); User user1 = (User) session.getAttribute("sessionUser"); ResultCode res = new ResultCode(); EntityWrapper<User> ew = new EntityWrapper<>(); ew.eq("user_name", user1.getUserName()); User user2= userService.selectOne(ew); if(user2.getPassWord().equals(AIAppUtils.encrypt(password))) { if (StringUtils.isNotBlank(password) && StringUtils.isNotBlank(newpassword)) { String setSql = "pass_word = " + "'" + AIAppUtils.encrypt(newpassword) + "'"; EntityWrapper<User> ew1 = new EntityWrapper<>(); ew.eq("user_id", user1.getUserID()); try { userService.updateForSet(setSql, ew1); session.removeAttribute("sessionUser"); res.setCode(0); } catch (Exception e) { // TODO: handle exception res.setCode(1); } } else { // 引數不能為空 res.setCode(1); res.setMsg("引數不能為空"); } }else { res.setCode(1); res.setMsg("原始密碼不正確!"); } return res; }