不支持你这么搞
最简复现: MainApplication.java
@SpringBootApplication public class MainApplication { public static void main(String[] args) { SpringApplication.run(MainApplication.class, args); } }
application.properties
spring.datasource.url=url... spring.datasource.username=user... spring.datasource.password=pwd...
注意这里,加上后insertFill就不再起作用!!!
mybatis-plus.configuration.global-config.banner=false
DemoEntity.java
@Getter @Setter @TableName("t_demo") public class DemoEntity implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(type = IdType.AUTO)
private Long id;
@TableField(fill = FieldFill.INSERT)
private Date createTime;
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
@TableField(select = false)
private Integer isDeleted;
}
DemoMapper.java
@Mapper
public interface DemoMapper extends BaseMapper
DemoTest.java
@Component
@RequiredArgsConstructor
public class DemoTest implements ApplicationListener
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
demoMapper.insert(new DemoEntity());
}
}
这个例子中,只要配置文件中配置了mybatis-plus.configuration.global-config前缀的任何属性,insertFill就会失效,因为只要配置了,MybatisConfigruation.setGlobalConfig就会被调用,之后再去调用GlobalConfigUtils.setGlobalConfig就无法覆盖了;
@miemieYaho 你看下
Originally posted by @heylear in https://github.com/baomidou/mybatis-plus/issues/3024#issuecomment-721119998
Comment From: miemieYaho
https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-boot-starter/src/main/java/com/baomidou/mybatisplus/autoconfigure/MybatisPlusProperties.java 117行
https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisConfiguration.java
Comment From: miemieYaho
Comment From: heylear
在注入MybatisPlusProperties时因为设置了mybatis-plus.configuration.global-config.banner属性会在bind过程中调用MybatisPlusProperties.configuration.setGlobalConfig方法,正如图所示的debug位置, 此时GlobalConfigUtils.GLOBAL_CONFIG已经有值了,然后待sqlfactory初始化后再去GlobalConfigUtils.setGlobalConfig由于使用putIfAbsent导致后面的metaObjectHandler没有设置生效
@miemieYaho 感谢大神的耐心解答,纯属交流,我项目可以移除这行配置,不影响业务;issue不再重开;
另:抱歉上面示例中没有贴自定义MetaObjectHandler类