当前位置: 首页 > article >正文

springboot的多模块开发

文章目录

    • springboot的多模块开发
      • 1.创建项目springboot-high
      • 2.在项目中添加模块
        • 1)springboot-common模块
        • 2)springboot-domain模块
        • 3)springboot-service模块
        • 4)springboot-web模块
          • 多模块开发引入jpa的实体类问题

springboot的多模块开发

springboot-high

|–springboot-common 模块 (DTO)

|–springboot-domain 模块 (entity)

|–springboot-service 模块 (业务模块)

|–springboot-web 模块 (页面模块)

1.创建项目springboot-high

父模块的不需要打包,设置内容为pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.dyit.springboot</groupId><artifactId>springboot-high</artifactId><version>1.0-SNAPSHOT</version><modules><module>springboot-common</module><module>springboot-domain</module><module>springboot-service</module></modules><packaging>pom</packaging><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><project.lombok.version>1.18.22</project.lombok.version><project.maven.verison>3.1</project.maven.verison></properties><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.5.10</version></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${project.lombok.version}</version></dependency></dependencies><!--打包插件--><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${project.maven.verison}</version><configuration><encoding>utf-8</encoding><source>${java.version}</source><target>${java.version}</target></configuration></plugin></plugins></build></project>

父模块中不需要进行源代码开发,因此我们删除删除src文件夹

idea中不显示某些文件夹或文件
在这里插入图片描述

2.在项目中添加模块

在这里插入图片描述

在这里插入图片描述

1)springboot-common模块
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>springboot-high</artifactId><groupId>com.dyit.springboot</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><groupId>com.dyit.springboot.common</groupId><artifactId>springboot-common</artifactId><description>springboot-high子模块: 定义必备的模块信息</description></project>

添加Swagger配置

<dependencies><!--swagger3 api测试框架--><dependency><groupId>io.springfox</groupId><artifactId>springfox-boot-starter</artifactId><version>${project.swagger.version}</version></dependency>
</dependencies>

添加Swagger配置类

package com.dyit.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;/*** Swagger配置类*/
@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注解

@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.book.controller;import com.dyit.springboot.book.service.IPublisherSevice;
import com.dyit.springboot.common.dto.HttpResp;
import com.dyit.springboot.common.dto.RespEnum;
import com.dyit.springboot.domain.entity.Publisher;import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.Date;
import java.util.List;
@Tag(name ="出版社模块")
@RestController
@RequestMapping("/api/publisher")public class PublisherController {@Autowiredprivate IPublisherSevice ips;@Operation(summary = "获取所以出版社信息方法")@GetMapping("/findAll")public HttpResp findAll() {List<Publisher> list = ips.findAll();return new HttpResp(RespEnum.FIND_ALL_BOOKS, list, new Date());}
}
2)springboot-domain模块
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>springboot-high</artifactId><groupId>com.dyit.springboot</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><groupId>com.dyit.springboot.domain</groupId><artifactId>springboot-domain</artifactId><description>springboot-high子模块: 定义领域模型</description></project>
3)springboot-service模块
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>springboot-high</artifactId><groupId>com.dyit.springboot</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><groupId>com.dyit.springboot.service</groupId><artifactId>springboot-service</artifactId><description>springboot-high子模块: 定义业务模型</description>
</project>
4)springboot-web模块
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>springboot-high</artifactId><groupId>com.dyit.springboot</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><groupId>com.dyit.springboot.web</groupId><artifactId>springboot-web</artifactId><description>springboot-high子模块:静态页面</description>
</project>
多模块开发引入jpa的实体类问题

需要扫描其他模块实体类位置要加上@EntityScan,不然会报错,因为默认是只扫描本模块@EntityScan(basePackages = “其它模块entity包的位置”)

@SpringBootApplication
@EntityScan(basePackages = "com.dyit.springboot.domain.entity")
public class ServiceApp {public static void main(String[] args) {SpringApplication.run(ServiceApp.class);}
}
http://www.lryc.cn/news/2421120.html

相关文章:

  • 开源网上商城程序(简介国内外开源网店系统)
  • 破解硬盘还原卡与还原精灵
  • 云南省增值税发票综合平台(修订版)----发票抵扣勾选教程---
  • 注册表无法修改解决
  • Android之MediaPlayer详解
  • Keil5-MDK 使用编译步骤及异常与修改(生成axf文件和bin文件)
  • 参观中关村软件园二期小记
  • 怎么完全卸载赛门铁克_赛门铁克(sep)卸载方法
  • Xcode5.1离线下载安装及使用iOS5模拟器进行开发调试的方法
  • Win2003安装简录
  • KindEditor编辑器 用法
  • 红雪iOS6.1.3不完美越狱教程
  • 魔域mysql下载_魔域3.2无敌版之富甲天下下载_魔域3.2无敌版下载_快吧单机游戏...
  • Linux小知识---关于socket的一些知识点
  • 网维服务器加硬盘,网维大师官网-帮助
  • 裸奔浏览器_谁动了我的浏览器主页?“技术霸凌”带来糟心事
  • WPA2破解教程(详细步骤)
  • 雷军,早已财富自由的人,依然在努力!
  • NoSQL数据库Redis--2
  • 天蓝色房间(密室逃脱三)攻略
  • Unity实现瞄准镜效果之美
  • PC装MAC OS 10.6雪豹系统教程
  • windows 执行CMD命令
  • Java爬虫实践:Jsoup+HttpUnit爬取今日头条、网易、搜狐、凤凰新闻
  • 开发WAP网站入门
  • 2021-03-01
  • .NET Framework 3.5 SP1 离线安装时下载文件问题及精简方法
  • chinaren同学录的字数倒记数
  • as3.0舞台自适应
  • 虚拟光驱DAEMONTools 3.47特别版/汇编版/珍藏版