mybatis plus 更新值为null的字段

栏目: IT技术 · 发布时间: 5年前

内容简介:转载请注明出处:由于mybatis plus调用默认的更新操作方法时,不更新值为空,null或默认值等得属性字段,只更新值为非null,非空非默认值的属性字段。以下为mybatis plus sample项目中一个对应数据库的实体类:

转载请注明出处:

由于mybatis plus调用默认的更新操作方法时,不更新值为空,null或默认值等得属性字段,只更新值为非null,非空非默认值的属性字段。

以下为mybatis plus sample项目中一个对应数据库的实体类:

import java.util.List;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;

import lombok.Data;

/**
 * @author miemie
 * @since 2019-11-27
 */
@Data
@TableName(resultMap = "m_b") // 对应xml里的 id
public class Man {

    private Long id;

    private String name;

    private Long laoPoId;

    @TableField(exist = false)
    private Woman laoPo;

    @TableField(exist = false)
    private List<Child> waWa;
}

调用 BaseMapper 其中默认的修改方法;

mybatis plus 更新值为null的字段

项目中我们经常需要对一些数据库字段就要进行置空或设为默认值的操作,需要在实体类上加一个注解就可以:

@TableField(updateStrategy = FieldStrategy.IGNORED )

在实体类上添加该注解就可以对这个字段进行空的默认值修改操作。对于新增也是一样的。

@TableField(insertStrategy= FieldStrategy.IGNORED )

 学习和研究mybatis plus项目可以学习这个项目: https://github.com/baomidou/mybatis-plus-samples

拿走不谢。点赞就好


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Intersectional Internet

The Intersectional Internet

Safiya Umoja Noble、Brendesha M. Tynes / Peter Lang Publishing / 2016

From race, sex, class, and culture, the multidisciplinary field of Internet studies needs theoretical and methodological approaches that allow us to question the organization of social relations that ......一起来看看 《The Intersectional Internet》 这本书的介绍吧!

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具