springboot实现CodeGenerator代码自动生成
1:在application.properties中加入数据库连接配置
# 服务端口 server.port=8001 # 服务名 spring.application.name=service-edu # 环境设置:dev、test、prod spring.profiles.active=dev # mysql数据库连接 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/qiyun?serverTimezone=GMT%2B8 spring.datasource.username=root spring.datasource.password=root #mybatis日志 mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
2:引入依赖 Mybatis Plus 代码生成器依赖
<!-- velocity 模板引擎, Mybatis Plus 代码生成器需要 --> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> </dependency>
3:复制一份CodeGenerator 文件放到test测试包下面,修改完内容以后,运行run方法 就会生成从mapper到controller的代码,里面需要改的地方已经标注了
