MybatisPlus修改時空字段無法修改的解決方案
MybatisPlus空字段無法修改

點開修改

數(shù)據(jù)為空時,點擊確定,可列表出現(xiàn)的數(shù)據(jù)還是為原來的數(shù)據(jù)
查看后臺的打印輸出,發(fā)現(xiàn)沒有更新的這2個字段
這個時候,在實體類中加入

這行注釋的意思是
在屬性執(zhí)行修改時,將自動填充一個值(默認(rèn)為null),即將字段修改為空,而不是不做修改。
Mybatis-Plus修改指定字段
核心代碼
/**
* 修改密碼(只能修改自己的密碼)
*
* @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<>();
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 {
// 參數(shù)不能為空
res.setCode(1);
res.setMsg("參數(shù)不能為空");
}
}else {
res.setCode(1);
res.setMsg("原始密碼不正確!");
}
return res;
}
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Spring中的@EnableScheduling定時任務(wù)注解
這篇文章主要介紹了Spring中的@EnableScheduling注解,@EnableScheduling是 Spring Framework 提供的一個注解,用于啟用 Spring 的定時任務(wù)功能,通過使用這個注解,可以在 Spring 應(yīng)用程序中創(chuàng)建定時任務(wù),需要的朋友可以參考下2024-01-01
springboot+rabbitmq實現(xiàn)智能家居實例詳解
這篇文章主要為大家介紹了springboot+rabbitmq實現(xiàn)智能家居的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
永中文檔在線轉(zhuǎn)換服務(wù)Swagger調(diào)用說明
這篇文章主要為大家介紹了永中文檔在線轉(zhuǎn)換服務(wù)Swagger調(diào)用說明,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06
詳解spring boot集成ehcache 2.x 用于hibernate二級緩存
本篇文章主要介紹了詳解spring boot集成ehcache 2.x 用于hibernate二級緩存,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05
一文學(xué)透ApplicationContext繼承接口功能及與BeanFactory區(qū)別
這篇文章主要為大家介紹了ApplicationContext繼承接口功能及與BeanFactory區(qū)別示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04

