
1、pom文件
org.springframework.boot spring-boot-starter-webcom.baomidou mybatis-plus-boot-starter3.4.0 com.baomidou mybatis-plus-generator3.0.5 org.apache.velocity velocity-engine-core2.0 mysql mysql-connector-java${mysql.version} io.springfox springfox-swagger2io.springfox springfox-swagger-uiorg.projectlombok lombokorg.freemarker freemarker2.3.30
2、application.yml
spring:
application:
name: jxc-base-web
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/purchase_sales_inventory?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
username: root
password: root
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
logic-delete-field: deleted
logic-delete-value: 1
logic-not-delete-value: 0
mapper-locations: classpath*:/mapper
public static String scanner(String tip) {
Scanner scanner = new Scanner(System.in);
StringBuilder help = new StringBuilder();
help.append("请输入" + tip + ":");
System.out.println(help.toString());
if (scanner.hasNext()) {
String ipt = scanner.next();
if (StringUtils.isNotBlank(ipt)) {
return ipt;
}
}
throw new MybatisPlusException("请输入正确的" + tip + "!");
}
public static void main(String[] args) {
// 创建代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir("D:\IDEA Project-2021\purchase_sales_inventory\jxc-base-web" + "/src/main/java");
// gc.setOutputDir(scanner("请输入你的项目路径")+ "\jxc-base-web\src\main\java");
// 作者名
gc.setAuthor("wangdanyang");
// 生成之后是否打开资源管理器
gc.setOpen(false);
// 重新生成时是否覆盖文件
gc.setFileOverride(false);
// 生成service代码 第一个字母为I
gc.setServiceName("%sService");
// 设置主键生成策略 自动增长
gc.setIdType(IdType.AUTO);
// 设置Data类型 只使用java.util.date代替
gc.setDateType(DateType.ONLY_DATE);
// 实体属性swagger2注解
gc.setSwagger2(true);
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://localhost:3306/purchase_sales_inventory?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("root");
// 使用mysql数据库
dsc.setDbType(DbType.MYSQL);
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName(null);
pc.setParent("com.wdy");
pc.setController("controller");
pc.setService("service");
pc.setServiceImpl("service.impl");
pc.setMapper("mapper");
pc.setEntity("entity");
pc.setXml("mapper");
mpg.setPackageInfo(pc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
//设置哪些表需要自动生成
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
//实体类名称驼峰命名
strategy.setNaming(NamingStrategy.underline_to_camel);
// 列名名称驼峰命名
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
// 使用简化getter和setter
strategy.setEntityLombokModel(true);
// 设置controller的api风格 使用RestController
strategy.setRestControllerStyle(true);
//驼峰转连字符
strategy.setControllerMappingHyphenStyle(true);
mpg.setStrategy(strategy);
mpg.execute();
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)