<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.0.5</version> </dependency> <!-- mybatis-plus 代码生成器需要的依赖 --> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> <version>2.0</version> </dependency>
public class PlusGenerator { public static final String projectPath = "D:\Users\Administrator\eclipse-workspace\mybatisplus\src\main\java\"; public static void main(String[] args) { generator(); } public static void generator() { // 代码生成器 AutoGenerator ag = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); gc.setAuthor("zhangsan"); gc.setOpen(false); gc.setOutputDir(projectPath); gc.setBaseResultMap(true); //xml resultmap // 自定义文件命名,注意 %s 会自动填充表实体属性! gc.setControllerName("%sController"); gc.setServiceName("%sService"); gc.setServiceImplName("%sServiceImpl"); gc.setMapperName("%sMapper"); gc.setXmlName("%sMapper"); ag.setGlobalConfig(gc); // 配置数据源 DataSourceConfig dsc = new DataSourceConfig(); dsc.setDbType(DbType.MYSQL); dsc.setDriverName("com.mysql.cj.jdbc.Driver"); dsc.setUsername("root"); dsc.setPassword("123456"); dsc.setUrl("jdbc:mysql://localhost:3306/dbtest?serverTimezone=GMT%2B8"); ag.setDataSource(dsc); // 包配置 PackageConfig pc = new PackageConfig(); pc.setParent("com.example.demo"); pc.setController("controller"); pc.setService("service"); pc.setServiceImpl("serviceImpl"); pc.setMapper("mapper"); pc.setEntity("entity"); pc.setXml("xml"); ag.setPackageInfo(pc); //策略配置 StrategyConfig strategy = new StrategyConfig(); //strategy.setTablePrefix(new String[] { "tb_" });// 此处可以修改为您的表前缀 strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略 strategy.setInclude(new String[] {"sc","course","teacher","student" }); // 需要生成的表 strategy.setSuperServiceClass(null); strategy.setSuperServiceImplClass(null); strategy.setSuperMapperClass(null); strategy.setRestControllerStyle(true); ag.setStrategy(strategy); ag.execute(); } }