使用IDE建立功能java
Intellij > File > New > Project > Spring Initializr
複製代碼
設置項目名稱,使用默認選項,建立空的主項目web
<!-- 模塊說明:這裏聲明多個子模塊 -->
<modules>
<module>btp-bean</module>
<module>btp-common</module>
<module>btp-dao</module>
<module>btp-service</module>
<module>btp-admin</module>
<module>btp-user</module>
</modules>
複製代碼
最終的pom.xml以下spring
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.boyuantang</groupId>
<artifactId>btp-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>btp-parent</name>
<description>Demo project for Spring Boot</description>
<packaging>pom</packaging>
<!-- 模塊說明:這裏聲明多個子模塊 -->
<modules>
<module>btp-bean</module>
<module>btp-common</module>
<module>btp-dao</module>
<module>btp-service</module>
<module>btp-admin</module>
<module>btp-user</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
</dependencies>
</project>
複製代碼
在IDE中點擊父項目,右鍵apache
New > Module > Spring Initializr
複製代碼
設置項目名稱,使用默認選項,建立空的子模塊json
取代默認的parent spring, 由於父項目已經繼承了parent springbash
<!-- 繼承本項目的父工程 -->
<parent>
<groupId>com.boyuantang</groupId>
<artifactId>btp-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
複製代碼
<dependency>
<groupId>com.boyuantang</groupId>
<artifactId>btp-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
複製代碼
非web模塊,最終的pom.xml以下mybatis
<?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>
<!-- 繼承本項目的父工程 -->
<parent>
<groupId>com.boyuantang</groupId>
<artifactId>btp-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.boyuantang</groupId>
<artifactId>btp-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>btp-dao</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.boyuantang</groupId>
<artifactId>btp-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
複製代碼
子模塊能夠分開打包。生成的jar可運行。app
@MapperScan
@MapperScan("com.boyuantang.dao")
@SpringBootApplication
public class BtpAdminApplication {
public static void main(String[] args) {
SpringApplication.run(BtpAdminApplication.class, args);
}
}
複製代碼
@ComponentScan
@ComponentScan("com.boyuantang")
@SpringBootApplication
public class BtpAdminApplication {
public static void main(String[] args) {
SpringApplication.run(BtpAdminApplication.class, args);
}
}
複製代碼
mybatis.mapper-locations=classpath*:mapper/*.xml
複製代碼
lombok
,fastjson
之類