mybatis-plus代码方式配置

2022-12-02 11:35:53 浏览数 (1)

发光的不全是黄金——莎士比亚

示例:https://github.com/apache/incubator-streampark/pull/2099

原来的方式:

代码语言:javascript复制
# mybatis plus setting
mybatis-plus:
  type-aliases-package: org.apache.streampark.console.*.entity
  mapper-locations: classpath:mapper/*/*.xml
  configuration:
    jdbc-type-for-null: null
  global-config:
    db-config:
      id-type: auto
    # close mybatis-plus banner
    banner: false

现在的方式:

代码语言:javascript复制
/**
    * mybatis plus setting
    *
    * @return MybatisPlusPropertiesCustomizer
    */
   @Bean
   public MybatisPlusPropertiesCustomizer mybatisPlusPropertiesCustomizer() {
       return properties -> {
           properties.setTypeAliasesPackage("org.apache.streampark.console.*.entity");
           properties.setMapperLocations(new String[]{"classpath:mapper/*/*.xml"});
           MybatisConfiguration mybatisConfiguration = new MybatisConfiguration();
           mybatisConfiguration.setJdbcTypeForNull(null);
           properties.setConfiguration(mybatisConfiguration);
           GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(mybatisConfiguration);
           GlobalConfig.DbConfig dbConfig = globalConfig.getDbConfig();
           dbConfig.setIdType(IdType.AUTO);
           // close mybatis-plus banner
           globalConfig.setBanner(false);
           properties.setGlobalConfig(globalConfig);
       };
   }

0 人点赞