2021-06-05

springboot+mybatis-plus快速生成项目模板

项目模板


1、项目概览


项目结构

image-20210605184255049

创建项目时,父项目用springboot,子项目用maven,父项目统一管理,子项目分模块

springboot父项目(子项目用maven建)- common模块- web模块- .......

父项目pom.

<properties> <!--java8--> <java.version>1.8</java.version> <!--mybatis-plus--> <mp.version>3.4.2</mp.version> <!--swagger--> <swagger.version>3.0.0</swagger.version> <!--velocity模板引擎--> <velocity.version>2.3</velocity.version> <!--java连接数据库--> <mysql-connect-java.version>8.0.25</mysql-connect-java.version> <!--velocity--> <velocity.version>2.3</velocity.version> <!--mybatis-plus-generator--> <mybatis-plus-generator.version>3.4.1</mybatis-plus-generator.version> <!--knife4j--> <knife4j.version>3.0.2</knife4j.version></properties><dependencyManagement> <dependencies>  <dependency>   <groupId>com.baomidou</groupId>   <artifactId>mybatis-plus-boot-starter</artifactId>   <version>${mp.version}</version>  </dependency>  <dependency>   <groupId>com.baomidou</groupId>   <artifactId>mybatis-plus-generator</artifactId>   <version>${mybatis-plus-generator.version}</version>  </dependency>  <dependency>   <groupId>org.apache.velocity</groupId>   <artifactId>velocity-engine-core</artifactId>   <version>${velocity.version}</version>  </dependency>  <dependency>   <groupId>io.springfox</groupId>   <artifactId>springfox-swagger2</artifactId>   <version>${swagger.version}</version>  </dependency>  <dependency>   <groupId>io.springfox</groupId>   <artifactId>springfox-swagger-ui</artifactId>   <version>${swagger.version}</version>  </dependency>  <dependency>   <groupId>mysql</groupId>   <artifactId>mysql-connector-java</artifactId>   <version>${mysql-connect-java.version}</version>  </dependency>    <dependency>    <groupId>com.github.xiaoymin</groupId>    <artifactId>knife4j-spring-boot-starter</artifactId>    <version>${knife4j.version}</version>  </dependency> </dependencies></dependencyManagement><build> <plugins>  <plugin>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-maven-plugin</artifactId>   <configuration>    <skip>true</skip>   </configuration>  </plugin> </plugins></build>

子项目pom.

<dependencies> <!--controller相关--> <dependency>  <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--mybatis-plus--> <dependency>  <groupId>com.baomidou</groupId>  <artifactId>mybatis-plus-boot-starter</artifactId> </dependency> <!--代码生成器--> <dependency>  <groupId>com.baomidou</groupId>  <artifactId>mybatis-plus-generator</artifactId> </dependency> <dependency>  <groupId>org.apache.velocity</groupId>  <artifactId>velocity-engine-core</artifactId> </dependency> <!--swagger--> <dependency>  <groupId>io.springfox</groupId>  <artifactId>springfox-swagger2</artifactId> </dependency> <dependency>  <groupId>io.springfox</groupId>  <artifactId>springfox-swagger-ui</artifactId> </dependency> <!--java连接数据库--> <dependency>  <groupId>mysql</groupId>  <artifactId>mysql-connector-java</artifactId> </dependency> <!--lombok--> <dependency>  <groupId>org.projectlombok</groupId>  <artifactId>lombok</artifactId> </dependency>  <!--knife4j--> <dependency>    <groupId>com.github.xiaoymin</groupId>    <artifactId>knife4j-spring-boot-starter</artifactId> </dependency></dependencies><build> <plugins>  <plugin>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-maven-plugin</artifactId>   <configuration>    <skip>true</skip>   </configuration>  </plugin> </plugins></build>

子项目web模块pom.

<dependencies> <dependency>  <groupId>cn.jie</groupId>  <artifactId>admin-base-common</artifactId>  <version>0.0.1-SNAPSHOT</version> </dependency></dependencies>

代码生成器

public class CodeGenerator { /**  * <p>  * 读取控制台内容  * </p>  */ 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();  String projectPath = scanner("项目路径");  //项目生成路径  gc.setOutputDir(projectPath + "/src/main/java");  gc.setAuthor("sky");  //打开资源管理器  gc.setOpen(false);  //开启swagger  gc.setSwagger2(true);  //覆盖文件  gc.setFileOverride(false);  gc.setServiceName("%sService");  //主键自增  gc.setIdType(IdType.AUTO);  //java.util.date  gc.setDateType(DateType.ONLY_DATE);  mpg.setGlobalConfig(gc);  // 数据源配置  DataSourceConfig dsc = new DataSourceConfig();  dsc.setUrl("jdbc:mysql://localhost:3306/adminweb?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8");  // dsc.setSchemaName("public");  dsc.setDriverName("com.mysql.cj.jdbc.Driver");  dsc.setUsername("root");  dsc.setPassword("root");  dsc.setDbType(DbType.MYSQL);  mpg.setDataSource(dsc);  // 包配置  PackageConfig pc = new PackageConfig();  pc.setModuleName(scanner("模块名"));  pc.setParent("cn.jie");  pc.setEntity("entity");  pc.setMapper("mapper");  pc.setController("controller");  pc.setService("service");  pc.setServiceImpl("service.impl");  mpg.setPackageInfo(pc);  // 策略配置  StrategyConfig strategy = new StrategyConfig();  //表  strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));  //驼峰命名  strategy.setNaming(NamingStrategy.underline_to_camel);  strategy.setColumnNaming(NamingStrategy.underline_to_camel);  //lombok  strategy.setEntityLombokModel(true);  //restful  strategy.setRestControllerStyle(true);  strategy.setControllerMappingHyphenStyle(true);  mpg.setStrategy(strategy);  mpg.execute(); }}

springboot配置

spring: application: name: admin-base-web datasource: type: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/adminweb?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8 username: root password: root jackson: date-format: yyyy-MM-dd HH:mm:ss time-zone: GMT+8server: port: 8081mybatis-plus: global-config: db-config:  logic-delete-field: deleted # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2)  logic-delete-value: 1 # 逻辑已删除值(默认为 1)  logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) mapper-locations: classpath*:/mapper/*.

image-20210605155015320

2、美化swagger-ui


swagger注意要用3.0.0版本

配置完swagger2config

@Configuration@EnableSwagger2@EnableKnife4j@Import(BeanValidatorPluginsConfiguration.class)public class Swagger2Config { @Bean(value = "defaultApi2") public Docket defaultApi2() {  Docket docket=new Docket(DocumentationType.SWAGGER_2)    .apiInfo(new ApiInfoBuilder()      //.title("swagger-bootstrap-ui-demo RESTful APIs")      .description("物资管理系统API文档")      .termsOfServiceUrl("https://www.cnblogs.com/thatbluesky/")      .contact(new Contact("我的博客","https://www.cnblogs.com/thatbluesky/","1879186403@qq.com"))      .version("1.0")      .build())    //分组名称    .groupName("1.0版本")    .select()    //这里指定Controller扫描包路径    .apis(RequestHandlerSelectors.basePackage("cn.jie.system.controller"))    .paths(PathSelectors.any())    .build();  return docket; }}

访问 src="https://gitee.com/wanrujie/sky/raw/master/20210605191057.png" alt="image-20210605191542280" loading="lazy">









原文转载:http://www.shaoqun.com/a/785269.html

跨境电商:https://www.ikjzd.com/

airwallex:https://www.ikjzd.com/w/1011

r标:https://www.ikjzd.com/w/1070

泛亚班拿:https://www.ikjzd.com/w/1262

3suisses:https://www.ikjzd.com/w/412


项目模板1、项目概览项目结构创建项目时,父项目用springboot,子项目用maven,父项目统一管理,子项目分模块springboot父项目(子项目用maven建)-common模块-web模块-.......父项目pom.<properties><!--java8--><java.version>1.8</java.version><!-
Poshmark:https://www.ikjzd.com/w/506
Typeform :https://www.ikjzd.com/w/522
蓝思科技:https://www.ikjzd.com/w/1039
PAYSBUY:https://www.ikjzd.com/w/1867
郭璐:https://www.ikjzd.com/w/2296
FORZIERI:https://www.ikjzd.com/w/2398
盐田快船:https://www.ikjzd.com/w/2739
口述:老公祸害我妹称为检查身体老公妹妹身体:http://lady.shaoqun.com/m/a/38559.html
口述:老公偷情三年竟说性是游戏:http://lady.shaoqun.com/m/a/44001.html
男友第一次去我家的经历 口述我和男朋友第一次约会详情:http://lady.shaoqun.com/a/269609.html
迷醉的偷情生活我很享受 女人口述和大学生的那些事:http://lady.shaoqun.com/a/275116.html
在草朵上日儿媳妇。一件令人难以启齿的乱伦秘事:http://lady.shaoqun.com/a/274566.html
少妇口述:一边霸占老公一边放纵偷情(2/2):http://www.30bags.com/a/249660.html
痛快酣畅 我沉迷于他刚猛的动作:http://www.30bags.com/a/252410.html
男友把套套藏进闺蜜的文胸:http://www.30bags.com/m/a/251707.html
口述:混乱同居等竟让我成为了同性恋:http://www.30bags.com/m/a/254107.html
有女友的他总想着和我爱爱 接受吗:http://www.30bags.com/m/a/252393.html

No comments:

Post a Comment