导入依赖
< dependency>
< groupId> com.baomidou</ groupId>
< artifactId> mybatis-plus-boot-starter</ artifactId>
< version> 3.0.5</ version>
</ dependency>
< dependency>
< groupId> com.baomidou</ groupId>
< artifactId> mybatis-plus-generator</ artifactId>
< version> 3.4.1</ version>
</ dependency>
< dependency>
< groupId> org.apache.velocity</ groupId>
< artifactId> velocity-engine-core</ artifactId>
< version> 2.0</ version>
</ dependency>
编写自动生成器,然后运行
public class AutoCode {
public static void main ( String [ ] args) {
AutoGenerator mpg = new AutoGenerator ( ) ;
GlobalConfig gc = new GlobalConfig ( ) ;
String projectPath = System . getProperty ( "user.dir" ) ;
gc. setOutputDir ( projectPath+ "/src/main/java" ) ;
gc. setAuthor ( "Strike" ) ;
gc. setOpen ( false ) ;
gc. setFileOverride ( false ) ;
gc. setServiceName ( "^%sService" ) ;
gc. setIdType ( IdType . ID_WORKER) ;
gc. setDateType ( DateType . ONLY_DATE) ;
gc. setSwagger2 ( true ) ;
mpg. setGlobalConfig ( gc) ;
DataSourceConfig dsc = new DataSourceConfig ( ) ;
dsc. setUrl ( "jdbc:mysql://localhost:3306/vueblog?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC" ) ;
dsc. setDriverName ( "com.mysql.cj.jdbc.Driver" ) ;
dsc. setUsername ( "root" ) ;
dsc. setPassword ( "123456" ) ;
dsc. setDbType ( DbType . MYSQL) ;
mpg. setDataSource ( dsc) ;
PackageConfig pc = new PackageConfig ( ) ;
pc. setModuleName ( "blog" ) ;
pc. setParent ( "com.strike" ) ;
pc. setEntity ( "entity" ) ;
pc. setMapper ( "mapper" ) ;
pc. setService ( "service" ) ;
mpg. setPackageInfo ( pc) ;
StrategyConfig strategyConfig = new StrategyConfig ( ) ;
strategyConfig. setInclude ( "m_blog" ) ;
strategyConfig. setNaming ( NamingStrategy . underline_to_camel) ;
strategyConfig. setColumnNaming ( NamingStrategy . underline_to_camel) ;
strategyConfig. setEntityLombokModel ( true ) ;
strategyConfig. setRestControllerStyle ( true ) ;
strategyConfig. setControllerMappingHyphenStyle ( true ) ;
mpg. setStrategy ( strategyConfig) ;
mpg. execute ( ) ;
}
}