前言
我们在做项目过程中用的差不多都是一个项目,但是这里如果遇到多个模块项目的需求怎么办呢?
下面就为大家带来如何用Idea新建SpringBoot多模块项目
一、新建一个demoTest项目
1、点击Creat New Project
2、选择Spring Initializr,点击next
3、把项目名字改为demotest,选择java8,点击next
4、直接next
5、删掉没用的,保留如图
二、新建demo-dao模块,选择依赖
建好demo-dao模块之后,删掉如图所示的文件
三、新建demo-service模块
新建方法跟demo-dao一样,只不过不需要选择依赖
删掉没用的,跟demo-dao一样,保留如图
四、跟新建demo-service一样新建demo-domain模块
一样删掉不需要的
五、新建demo-web模块,不用删任何东西,需要添加依赖
完整的目录
在demo-web的pom中添加以下依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
修改如图所示的代码,指定父模块
修改后的demo-web的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>demotest</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.example</groupId>
<artifactId>demo-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo-web</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>demo-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>demo-dao</artifactId>
<version>0.0