1 Springboot多模块开发总结
1.1 创建新项目1.2 在项目中添加模块
1.2.1 springboot-common模块 1.2.2 springboot-domain模块1.2.3 springboot-service模块1.2.4 springboot-web模块
1 Springboot多模块开发总结springboot-high
springboot-common 公共模块 (DTO)springboot-domain 域模块(entity)(领域模型,完成实体类和表的映射)springboot-service 业务模块
1.1 创建新项目一般一个项目,几十个模块,大模块下面有小模块,小模块下面有类和方法。
父模块不需要打包,设置内容为pom
1.引入依赖;模块中不需要进行源代码开发,所以删除src文件夹
2.new Mudule,添加三个新模块,springboot-common/domain/service
groupId: com.qfy.springboot.common/domain/service
4.0.0 com.qfy.springboot springboot-epi 1.0-SNAPSHOT springboot-common springboot-domain springboot-service pom 8 8 1.18.22 3.1 3.0.0 8.0.28 1.2.8 4.12 org.springframework.boot spring-boot-starter-parent 2.5.10 org.springframework.boot spring-boot-starter-web org.projectlombok lombok org.apache.maven.plugins maven-compiler-plugin 3.1 utf-8 ${java.version} ${java.version}
1.2 在项目中添加模块 1.2.1 springboot-common模块
3.idea中不显示某些文件夹或文件(输入.ideah后要按回车)
springboot-epi com.qfy.springboot 1.0-SNAPSHOT ../../springboot-epi 4.0.0 com.qfy.springboot.common springboot-common springboot-high子模块:定义必备的模块信息
添加Swagger配置
io.springfox springfox-boot-starter ${project.swagger.version}
添加Swagger配置类SwaggerConfiguration
package com.qfy.springboot.common.config;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.documentationType;
import springfox.documentation.spring.web.plugins.Docket;
@Configuration
public class SwaggerConfiguration {
public Docket createRestApi() {
return new Docket(documentationType.OAS_30)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(Operation.class))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("springboot整合swagger3的接口文档")
.description("描述图书管理的接口文档")
.contact(new Contact("非凡boot", "http://www.diyt.com", "dyit@dyit.com"))
.version("1.0")
.build();
}
}
DTO注解
package com.dyit.springboot.common.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Schema(description = "DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class HttpResp {
@Schema(description = "代码和描述")
RespEnum resp;
@Schema(description = "返回结果")
private Object results;
@Schema(description = "DTO对象创建的时间")
private Date date;
}
package com.dyit.springboot.common.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Schema(description = "DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class HttpResp {
@Schema(description = "代码和描述")
RespEnum resp;
@Schema(description = "返回结果")
private Object results;
@Schema(description = "DTO对象创建的时间")
private Date date;
}
1.2.2 springboot-domain模块
1.2.3 springboot-service模块springboot-high com.dyit.springboot 1.0-SNAPSHOT ../../springboot-highxxxx 4.0.0 com.dyit.springboot.domain springboot-domain springboot-high子模块: 定义领域模型 org.springframework.boot spring-boot-starter-data-jpa
1.2.4 springboot-web模块springboot-high com.dyit.springboot 1.0-SNAPSHOT ../../springboot-highxxxx 4.0.0 com.dyit.springboot.service springboot-service springboot-high子模块: 定义业务模型 com.dyit.springboot.domain springboot-domain 1.0-SNAPSHOT com.dyit.springboot.common springboot-common 1.0-SNAPSHOT mysql mysql-connector-java ${project.mysql.version} com.alibaba druid-spring-boot-starter ${project.druid.version} junit junit ${project.test.version} test org.springframework.boot spring-boot-starter-test test org.apache.poi poi-ooxml 5.0.0 org.springframework.boot spring-boot-maven-plugin
springboot-high com.dyit.springboot 1.0-SNAPSHOT ../../springboot-high 4.0.0 com.dyit.springboot.web springboot-web springboot-high子模块:静态页面



