34.项目模块化
Maven配置
找到maven的settings.xml
<profile>
<id>jdk-1.8</id>
<activation>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
文件夹改动
先关闭项目左上角-文件-关闭项目,再进入项目工程文件夹,删除除了src和pom.xml外的所有文件,并更改文件夹名为vhr-web,
到文件夹中除了src和pom.xml将其他的文件都删除
创建maven新项目vhr,不选骨架直接点下一步,创建模块vhrserver,父工程为vhr
继续添加vhr-mapper、vhr-service、vhr-model,注意此时父工程为vhrserver
项目改造
关闭项目,在vhr文件夹中保留vhrserver、src和pom.xml,在vhrserver文件夹中保留vhr-mapper、vhr-service、vhr-model和pom.xml,然后在各个模块文件夹中保留src和pom.xml,最后将vhr-web剪切到vhrserver中。
打开项目,在vhr-web的pom.xml中,右键单击,选择Add as Maven Project
将其中的parent标签剪切到vhr的pom.xml中
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
给vhr-web添加parent
<parent>
<artifactId>vhrserver</artifactId>
<groupId>org.javaboy</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
在vhrserver中添加module
<module>vhr-web</module>
给vhr-mapper/pom.xml添加vhr-model依赖
<dependencies>
<dependency>
<groupId>org.javaboy</groupId>
<artifactId>vhr-model</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
给vhr-service/pom.xml添加vhr-mapper依赖
<dependencies>
<dependency>
<groupId>org.javaboy</groupId>
<artifactId>vhr-mapper</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
给vhr-web/pom.xml添加vhr-service依赖
<dependency>
<groupId>org.javaboy</groupId>
<artifactId>vhr-service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
将vhr-web/pom.xml中的spring-boot-starter-security依赖剪切到vhr-service和vhr-model
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
将vhr-web/pom.xml中的spring-boot-starter-web依赖剪切到vhr-model中
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
将vhr-web/pom.xml中的poi依赖剪切到vhr-service中
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.1</version>
</dependency>
将vhr-web/pom.xml中的数据库相关的两个依赖剪切到vhr-mapper中
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.21</version>
</dependency>
在vhr-mapper/pom.xml中添加
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
接下来在各模块创建org.javaboy.vhr,这样是为了对应之前写的文件内的路径,然后将vhr-web中的service、mapper、utils、model分到对应模块中
重新启动项目,启动前端,测试登录。