11、基于 ssm 多模块项目案例
1、多项目模块划分
meinian-mobile-web: 美年旅游项目的用户系统
meinian-web: 美年旅游项目的管理员系统
meinian-service: 美年旅游项目的业务逻辑层
meinian-dao : 美年旅游项目的持久化层
meinian-bean : 美年旅游项目的Model 封装
2、项目搭建前配置分析
3、代码演示
代码和配置文件同单体ssm 一样。只不过做了拆分。
上传的为zip文件,由于不能上传zip文件所以存为了psd文件
4、settings.gradle 文件中
rootProject.name = 'meinian-parent'
include 'meinian-bean'
include 'meinian-dao'
include 'meinian-service'
include 'meinian-web'
include 'meinian-mobile-web'
5、在根工程 build.gradle 文件中抽取子模块的公共配置
group 'com.atguigu'
version '1.0-SNAPSHOT'
subprojects {
//添加插件
apply plugin: 'java'
apply plugin: 'java-library'//支持api
//编码环境jdk版本
sourceCompatibility = 1.8
//编译时jdk版本
targetCompatibility = 1.8
group 'com.atguigu'
version '1.0-SNAPSHOT'
//配置外部属性
ext {
spring_version = "4.3.6.RELEASE"
}
//依赖的配置
dependencies {
//lombok
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
implementation 'log4j:log4j:1.2.17'
//implementation 'org.slf4j:slf4j-api:1.7.25'
}
test {
useJUnitPlatform()
}
}
6、在根工程的build.gradle 文件中配置各个模块的依赖信息
project("meinian-bean"){
dependencies {
api 'org.projectlombok:lombok:1.18.24'
}
}
project("meinian-dao"){
dependencies {
api project(':meinian-bean')
api 'org.mybatis:mybatis-spring:1.2.3'
api 'com.alibaba:druid:1.0.15'
api 'org.mybatis:mybatis:3.3.0'
api 'mysql:mysql-connector-java:5.1.36'
}
}
project("meinian-service"){
dependencies {
api project(':meinian-dao')
api 'org.springframework:spring-web:4.1.7.RELEASE'
api 'org.springframework:spring-test:4.0.5.RELEASE'
api 'org.springframework:spring-jdbc:4.1.7.RELEASE'
api 'org.aspectj:aspectjweaver:1.8.6'
}
}
project("meinian-web"){
apply plugin: 'war'
dependencies {
implementation project(':meinian-service')
implementation 'org.springframework:spring-webmvc:4.1.7.RELEASE'
implementation "com.fasterxml.jackson.core:jackson-databind:2.2.3"
implementation "com.fasterxml.jackson.core:jackson-annotations:2.2.3"
implementation "com.fasterxml.jackson.core:jackson-core:2.2.3"
compileOnly 'javax.servlet:servlet-api:2.5'
implementation 'jstl:jstl:1.2'
}
}
project("meinian-mobile-web"){
apply plugin: 'war'
dependencies {
//implementation project(':meinian-bean')
implementation project(':meinian-service')
implementation 'org.springframework:spring-webmvc:4.1.7.RELEASE'
implementation "com.fasterxml.jackson.core:jackson-databind:2.2.3"
implementation "com.fasterxml.jackson.core:jackson-annotations:2.2.3"
implementation "com.fasterxml.jackson.core:jackson-core:2.2.3"
implementation 'jstl:jstl:1.2'
}
}
抽取之后,各子模块的build.gradle 文件就不用配置了。