很重要的功能:
参考官网:
https://baomidou.com/pages/779a6e/#快速入门
mybatis-plus自动帮你生成pojo controller .....东西
没啥废话上代码
这个依赖:
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.0</version>
</dependency>
测试类class文件用来生成
package ji;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
public class Code {
public static void main(String[] args) {
//构建一个代码生成器对象
AutoGenerator generator = new AutoGenerator();
//1、全局配置
GlobalConfig globalConfig = new GlobalConfig();
//获取当前目录
String path = System.getProperty("user.dir");
//输出到哪个目录
globalConfig.setOutputDir(path + "/src/main/java");
globalConfig.setAuthor("高低远近");
globalConfig.setOpen(false); //不打开文件夹
globalConfig.setFileOverride(false); //是否覆盖
globalConfig.setServiceName("%sService");//去Service的I前缀
// globalConfig.setIdType(IdType.AUTO);
// globalConfig.setDateType(DateType.ONLY_DATE);
globalConfig.setSwagger2(true);
generator.setGlobalConfig(globalConfig);
//2、设置数据源
DataSourceConfig dataSourceConfig = new DataSourceConfig();
dataSourceConfig.setUsername("root");
dataSourceConfig.setPassword("root");
dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/mybatis_pluss?useSSL=false&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8");
dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");
dataSourceConfig.setDbType(DbType.MYSQL);
generator.setDataSource(dataSourceConfig);
//3、包的配置
PackageConfig packageConfig = new PackageConfig();
packageConfig.setParent("ji");
packageConfig.setEntity("entity");
packageConfig.setMapper("mapper");
packageConfig.setService("service");
packageConfig.setController("controller");
generator.setPackageInfo(packageConfig);
//4、策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setInclude("user");//设置要映射的表名,只需改这里即可
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
strategy.setEntityLombokModel(true);//是否使用lombok开启注解
generator.execute();
}
}
效果如图
可参考别人的笔记:https://www.kuangstudy.com/bbs/1366329082232467457
标签:mybatisplus,generator,生成器,36,baomidou,mybatis,import,globalConfig,com From: https://www.cnblogs.com/gaodiyuanjin/p/18158520