Mybatis-Plus修改指定字段

 

核心代码  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 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 ew1 = new EntityWrapper<>();

				ew1.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;
	}

 

你可能感兴趣的:(Mybatis-Plus修改指定字段)