# core-starter 组件说明

# core-starter

diboot-core-starter 是基于diboot-core组件的starter封装,包含Dictionary字典表service和mapper实现、BindDict字典绑定的实现、自动安装字典表,以及默认配置HttpMessageConverters和Mybatis-plus的分页。

# 1. 引入依赖

Maven

<dependency>
    <groupId>com.diboot</groupId>
    <artifactId>diboot-core-spring-boot-starter</artifactId>
    <version>{latestVersion}</version>
</dependency>
1
2
3
4
5

或Gradle:

compile("com.diboot:diboot-core-spring-boot-starter:{latestVersion}")
1

# 2. 配置参数(数据源)

  • 以Mysql为例,配置数据源如下:
#datasource config
spring.datasource.url=jdbc:mysql://localhost:3306/diboot_example?characterEncoding=utf8&serverTimezone=GMT%2B8
spring.datasource.username=diboot
spring.datasource.password=123456
spring.datasource.hikari.maximum-pool-size=5
spring.datasource.hikari.driver-class-name=com.mysql.cj.jdbc.Driver
1
2
3
4
5
6

注:@BindDict注解需要依赖dictionary表,diboot-core starter 初次启动时会自动创建该表。

  • diboot-core-spring-boot-starter的可选参数配置:
# 是否初始化sql,默认true,初始化之后(或非开发环境)可以改为false关闭检测
diboot.core.init-sql=false
1
2

# 3. 配置config类:

diboot-core-starter默认预置了mybatis-plus的分页配置(使用mybatis-plus 3.4.x的MybatisPlusInterceptor最新配置方式)。 如果您依赖的是core-starter,则无需再次配置mybatis-plus的分页。 同时core-starter中也默认配置了MappingJackson2HttpMessageConverter,如果需要更改默认配置, 则需要在配置类中重新定义jacksonMessageConverter。

@Bean
public MappingJackson2HttpMessageConverter jacksonMessageConverter(){
    ...
}
1
2
3
4

注意:diboot-core-starter预置了默认的配置以及字典表相关的接口实现,如果是老项目中仅依赖diboot-core(非diboot-core-starter),则还需要将diboot的包路径加入ComponentScan中。

# 4. 最佳实践建议

  • 统一数据库表列名定义的大小写,除ORACLE和达梦可全大写外,其他库建议统一全小写+_(规避大小写混合的各种坑)。
  • 建议自定义自己的Base类,避免直接继承core中的Base类,便于后期扩展。 启用devtools,可一键生成初始自定义Base类代码到本地。
  • 新项目建议使用 diboot-core-starter自动配置及建表,mybatis-plus老项目可以尝试依赖diboot-core并手动配置并实现字典绑定接口。

使用过程中遇到问题,可加群交流。