ZBLOG

FastAutoGenerator.create("url", "username", "password") .globalConfig(builder -> { builder.author("baomidou") // 设置作者 .enableSwagger() // 开启 swagger 模式 .fileOverride() //

可以将这段代码封装成一个方法,如下所示:

  1. public void generateCode(String url, String username, String password) {
  2. FastAutoGenerator.create(url, username, password)
  3. .globalConfig(builder -> {
  4. builder.author("baomidou") // 设置作者
  5. .enableSwagger() // 开启 swagger 模式
  6. .fileOverride() // 覆盖已生成文件
  7. .outputDir("D://"); // 指定输出目录
  8. })
  9. .dataSourceConfig(builder -> builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
  10. int typeCode = metaInfo.getJdbcType().TYPE_CODE;
  11. if (typeCode == Types.SMALLINT) {
  12. // 自定义类型转换
  13. return DbColumnType.INTEGER;
  14. }
  15. return typeRegistry.getColumnType(metaInfo);
  16. }))
  17. .packageConfig(builder -> {
  18. builder.parent("com.baomidou.mybatisplus.samples.generator") // 设置父包名
  19. .moduleName("system") // 设置父包模块名
  20. .pathInfo(Collections.singletonMap(OutputFile.xml, "D://")); // 设置mapperXml生成路径
  21. })
  22. .strategyConfig(builder -> {
  23. builder.addInclude("t_simple") // 设置需要生成的表名
  24. .addTablePrefix("t_", "c_"); // 设置过滤表前缀
  25. })
  26. .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
  27. .execute();
  28. }

然后在调用处传入对应的参数即可使用。

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=2036

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?