在mybatis的基础上,封装了 很多现成的插删改查的方法。
public static void main(String[] args) {
// String[] tables={ "governance_metric","governance_type","governance_assess_detail"};
// String[] tables={ "t_ds_task_definition","t_ds_task_instance"};
// String[] tables={ "governance_assess_table","governance_assess_tec_owner","governance_assess_global"};
String[] tables={ "table_meta_info","table_meta_info_extra" };
FastAutoGenerator.create("jdbc:mysql://hadoop102:3306/dga","root","000000")
.globalConfig(builder -> {
builder.author("zhangchen") //作者
.outputDir("D:\\Code\\code_java\\data-governance-assesment\\src\\main\\java") //输出路径(写到java目录)
.commentDate("yyyy-MM-dd")
.dateType(DateType.ONLY_DATE); //选择实体类中的日期类型 ,Date or LocalDatetime
})
.packageConfig(builder -> { //各个package 名称
builder.parent("com.atguigu.dga")
.moduleName("meta")
.entity("bean")
.service("service")
.serviceImpl("service.impl")
.controller("controller")
.mapper("mapper");
})
.strategyConfig(builder -> {
builder.addInclude(tables)
.serviceBuilder()
.formatServiceFileName("%sService") //类后缀
.formatServiceImplFileName("%sServiceImpl") //类后缀
.entityBuilder()
.enableLombok() //允许使用lombok
.controllerBuilder()
.formatFileName("%sController") //类后缀
.enableRestStyle() //生成@RestController 否则是@Controller
.mapperBuilder()
//生成通用的resultMap 的xml映射
.enableBaseResultMap() //生成xml映射
.superClass(BaseMapper.class) //标配
.formatMapperFileName("%sMapper") //类后缀
.enableFileOverride() //生成代码覆盖已有文件 谨慎开启
.mapperAnnotation(Mapper.class) ; //生成代码Mapper上自带@Mapper
})
.templateConfig(new Consumer<TemplateConfig.Builder>() {
@Override
public void accept(TemplateConfig.Builder builder) {
// 实体类使用我们自定义模板
builder.entity("templates/myentity.java");
}
})
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
.execute();
}
debug
info
warn
error
logging.level.root=info #全局日志级别
logging.level.com.atguigu.dga.meta.mapper=debu #数据层日志级别,为了查看SQL
作用:复用
参数 | 作用 |
---|---|
initial-size | 初始连接数 |
min-idle | 最少保持空闲连接数 |
max-active | 最大可活动的连接数 |
max-wait | 最长等待时长 |
test-on-borrow | 借走时测试 |
test-while-idle | 空闲时测试 |
test-on-return | 归还时测试 |
# druid的多数据源配置和多数据源插件的自动配置有冲突,排除掉druid的配置
spring.autoconfigure.exclude=com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
spring.datasource.dynamic.datasource.demo.url=jdbc:mysql://hadoop102:3306/dga?characterEncoding=utf-8&useSSL=false
spring.datasource.dynamic.datasource.demo.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.dynamic.datasource.demo.username=root
spring.datasource.dynamic.datasource.demo.password=000000
spring.datasource.dynamic.datasource.demo.druid.initial-size=5
spring.datasource.dynamic.datasource.demo.druid.min-idle=5
spring.datasource.dynamic.datasource.demo.druid.max-active=20
spring.datasource.dynamic.datasource.demo.druid.max-wait=60000
spring.datasource.dynamic.datasource.demo.druid.test-on-borrow=true
spring.datasource.dynamic.datasource.demo.druid.test-while-idle=true
spring.datasource.dynamic.datasource.demo.druid.test-on-return=false
#spring.datasource.dynamic.datasource.demo2.url=jdbc:mysql://hadoop102:3306/atguigu?characterEncoding=utf-8&useSSL=false
#spring.datasource.dynamic.datasource.demo2.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.datasource.dynamic.datasource.demo2.username=root
#spring.datasource.dynamic.datasource.demo2.password=000000
#spring.datasource.dynamic.datasource.demo2.druid.initial-size=5
#spring.datasource.dynamic.datasource.demo2.druid.min-idle=5
#spring.datasource.dynamic.datasource.demo2.druid.max-active=20
#spring.datasource.dynamic.datasource.demo2.druid.max-wait=60000
#spring.datasource.dynamic.datasource.demo2.druid.test-on-borrow=true
#spring.datasource.dynamic.datasource.demo2.druid.test-while-idle=true
#spring.datasource.dynamic.datasource.demo2.druid.test-on-return=false