最近搜索

mybatis-plus 强制 更新某个是 null 怎么办

浏览:29
管理员 2025-05-16 18:32


一般情况下属性是null是不更新的。但是需要更新的时候呢。


更新  属性  是null  


更新  字段  是null  


更新  数据库 属性 字段  是null  




/**
 * /admin/index/type/update
 */
@ResponseBody
@RequestMapping("/update")
public JSONObject update(IndexType indexType, HttpServletResponse response, HttpServletRequest request) throws Exception {
    JSONObject result = new JSONObject();
    String webPath = request.getServletContext().getRealPath("");

    //更新的时候,判断一下, 有没有设置 goodsTYpeid是null
    indexTypeService.updateById(indexType);


    if(indexType.getGoodsTypeId()==null){
        UpdateWrapper<IndexType> wrapper = new UpdateWrapper<>();
        wrapper.lambda()
                .set(IndexType::getGoodsTypeId, null)  // 实体类属性名
                .eq(IndexType::getId, indexType.getId());
        indexTypeService.update(wrapper);
    }

    result.put("success", true);
    result.put("msg", "修改成功");
    return result;
}




联系站长

站长微信:xiaomao0055

站长QQ:14496453