File --> New --> Project ,选择 “ Spring Initalizr ” ,点击 Next

Next

Next --> Finish

右键根目录,New --> Module
选择 “ Spring Initializr ”,点击Next

此处注意Type选择Maven,Artifact根据自己的分模块的标准进行命名,可以按功能分模块(比如:订单、支付、登陆等模块分,就可以命名为order、pay、login等),此处我按照公共模块,业务模块、工具模块等模块进行划分的。

Next

Next --> Finish

重复上述步骤,根据自身需要再创建其他子模块

子模块
- "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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0modelVersion>
- <parent>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-parentartifactId>
- <version>2.7.5version>
- <relativePath/>
- parent>
-
- <groupId>com.hnggroupId>
- <artifactId>businessartifactId>
- <version>0.0.1-SNAPSHOTversion>
- <name>businessname>
- <description>业务模块description>
- <properties>
- <java.version>8java.version>
- properties>
-
- <dependencies>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-webartifactId>
- dependency>
-
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-testartifactId>
- <scope>testscope>
- dependency>
- dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-maven-pluginartifactId>
- plugin>
- plugins>
- build>
-
- project>
父模块
- "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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0modelVersion>
- <groupId>com.hnggroupId>
- <artifactId>serverartifactId>
- <version>0.0.1-SNAPSHOTversion>
- <name>servername>
- <description>父模块description>
- <packaging>pompackaging>
- <parent>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-parentartifactId>
- <version>2.7.5version>
- <relativePath/>
- parent>
-
- <properties>
- <java.version>8java.version>
- properties>
-
-
- <modules>
- <module>commonmodule>
- <module>businessmodule>
- <module>systemmodule>
- <module>toolsmodule>
- modules>
-
- <dependencies>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-webartifactId>
- dependency>
-
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-testartifactId>
- <scope>testscope>
- dependency>
- dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-maven-pluginartifactId>
- plugin>
- plugins>
- build>
-
- project>
四、删除多余不必要的文件及目录
1.删除所有子模块的 mvnw、mvnw.cmd、xxx.iml 文件及 .mvn 文件夹

2.删除所有子模块resources文件夹

3.删除所有子模块的的启动类

五、在主模块中添加测试代码,启动项目测试
在主模块business中创建对应的包controller、service等,在controller创建测试代码
- package com.hng.business.controller;
-
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
-
- /**
- * @Author 郝南过
- * @Date 2023/11/3 12:21
- * @Version 1.0
- */
- @RestController
- public class TestController {
-
- @RequestMapping("/test")
- public String hello(){
- return "Hello";
- }
- }
使用主模块business的启动文件启动项目,访问localhost:8080/test,可以正常看到响应(默认端口为8080,如需要修改可在主模块business下的resources下的application.properties文件中进行配置修改)
