Generator.kt 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package com.gxzc.zen
  2. import com.baomidou.mybatisplus.generator.AutoGenerator
  3. import com.baomidou.mybatisplus.generator.config.DataSourceConfig
  4. import com.baomidou.mybatisplus.generator.config.GlobalConfig
  5. import com.baomidou.mybatisplus.generator.config.PackageConfig
  6. import com.baomidou.mybatisplus.generator.config.StrategyConfig
  7. import com.baomidou.mybatisplus.generator.config.rules.DbType
  8. import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy
  9. /**
  10. *
  11. * @author NorthLan
  12. * @date 2018/1/24
  13. * @url https://noahlan.me
  14. */
  15. fun main(args: Array<String>) {
  16. val mpg = AutoGenerator()
  17. // 全局配置
  18. val gc = GlobalConfig()
  19. with(gc) {
  20. outputDir = "D://Test"
  21. isFileOverride = true
  22. isActiveRecord = false
  23. isEnableCache = false
  24. isOpen = true
  25. author = "NorthLan"
  26. isKotlin = true
  27. isBaseResultMap = true
  28. mapperName = "%sDao"
  29. xmlName = "%sDao"
  30. serviceName = "I%sService"
  31. serviceImplName = "%sServiceImpl"
  32. }
  33. mpg.globalConfig = gc
  34. // 数据源
  35. val dataSource = DataSourceConfig()
  36. with(dataSource) {
  37. dbType = DbType.MYSQL
  38. // typeConvert
  39. driverName = "com.mysql.jdbc.Driver"
  40. username = "root"
  41. password = "root"
  42. url = "jdbc:mysql://127.0.0.1:3306/rest?characterEncoding=utf8"
  43. }
  44. mpg.dataSource = dataSource
  45. // 策略配置
  46. val strategy = StrategyConfig()
  47. with(strategy) {
  48. setDbColumnUnderline(true)
  49. isCapitalMode = false
  50. naming = NamingStrategy.underline_to_camel
  51. // setTablePrefix()
  52. superEntityClass = "com.gxzc.zen.persistence.BaseModel"
  53. setSuperEntityColumns("id", "createBy", "createTime", "updateBy", "updateTime", "remark", "enable")
  54. superMapperClass = "com.gxzc.zen.persistence.BaseMapper"
  55. superServiceClass = "com.gxzc.zen.persistence.BaseService"
  56. superServiceImplClass = "com.baomidou.mybatisplus.service.impl.ServiceImpl"
  57. // superControllerClass = ""
  58. setInclude("user")
  59. isEntityBooleanColumnRemoveIsPrefix = true
  60. logicDeleteFieldName = "enable"
  61. // setExclude("")
  62. }
  63. mpg.strategy = strategy
  64. // 包配置
  65. val pc = PackageConfig()
  66. with(pc) {
  67. parent = "com.gxzc.zen.persistence"
  68. // moduleName = "test"
  69. entity = "model"
  70. }
  71. mpg.packageInfo = pc
  72. mpg.execute()
  73. }