版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
能看到这篇博客的肯定已经了解了相关知识,照着弄吧
项目创建完毕之后,项目的父子从属关系存在于父级项目的settings.gradle这个文件中
一、创建父级项目
1、左上角-->file-->new project
2、输入项目三坐标,version不用管
3、注意选择自己的gradle组件
4、项目创建完毕如下,我们称之为父容器
二、创建项目模块
2.1、common
1、右键父容器-->new module
2、输入ArtifactId,其他默认
3、项目创建完毕结构如下,可以看到父容器中settings.xml已经引入了子模块common
2.2、按照上述步骤,依次创建entity、dao、service这几个模块
2.3、创建controller模块,注意,这个模块是一个web工程
1、右键父容器-->new module
2、
输入ArtifactId,其他默认
3、项目创建完毕结构如下
三、jar包依赖
1、
这个依赖要放在父级项目的build.gradle文件中
group 'com.jk'
version '1.0-SNAPSHOT'
//添加所有项目的共享配置
subprojects {
//添加插件
apply plugin: 'java'
//编码环境jdk版本
sourceCompatibility = 1.7
//编译时jdk版本
targetCompatibility = 1.7
//仓库的配置
repositories {
//配置私服
maven {url "http://192.168.31.200:8081/nexus/content/groups/public/"}
//maven中央仓库
mavenCentral()
}
//配置外部属性
ext {
spring_version = "4.1.6.RELEASE"
}
//依赖的配置
dependencies {
// 和Maven类似,gradle导入依赖包也可以定义其作用的生命周期:
// compile:编译时必须。
// runtime:运行时必须,包括编译时。
// testCompile:测试编译时必须。
// testRuntime:测试运行时必须,包括编译时。
// 注:此外配置依赖包,还可以模块化配置、导入list、配置是否传递等。
//单元测试
testCompile group: 'junit', name: 'junit', version: '4.12'
//servlet依赖
compile "javax.servlet:servlet-api:3.0-alpha-1"
compile "javax:javaee-api:7.0"
//jstl标签库
compile "taglibs:standard:1.1.2"
compile "javax.servlet:jstl:1.2"
//公共资源包
compile "commons-logging:commons-logging:1.2"
compile "commons-lang:commons-lang:2.6"
compile "org.apache.commons:commons-collections4:4.0"
compile "commons-beanutils:commons-beanutils:1.8.3"
compile "commons-dbcp:commons-dbcp:1.4"
compile "commons-pool:commons-pool:1.6"
//文件上传
compile "commons-fileupload:commons-fileupload:1.3.1"
compile "commons-io:commons-io:2.4"
//AspectJ(切点表达式)
compile "org.aspectj:aspectjrt:1.7.4"
compile "org.aspectj:aspectjweaver:1.7.4"
//springmvc + Spring Configuration
compile "org.springframework:spring-web:$spring_version"
compile "org.springframework:spring-webmvc:$spring_version"
compile "org.springframework:spring-aop:$spring_version"
compile "org.springframework:spring-aspects:$spring_version"
compile "org.springframework:spring-beans:$spring_version"
compile "org.springframework:spring-context:$spring_version"
compile "org.springframework:spring-context-support:$spring_version"
compile "org.springframework:spring-core:$spring_version"
compile "org.springframework:spring-expression:$spring_version"
compile "org.springframework:spring-jdbc:$spring_version"
compile "org.springframework:spring-messaging:$spring_version"
compile "org.springframework:spring-orm:$spring_version"
compile "org.springframework:spring-tx:$spring_version"
compile "org.springframework:spring-test:$spring_version"
//MyBatis
compile "org.mybatis:mybatis:3.0.5"
//mybatis spring 插件
compile "org.mybatis:mybatis-spring:1.0.1"
//数据库驱动
compile "mysql:mysql-connector-java:5.1.23"
compile "com.jk.oracle:ojdbc14:1.1.14"
//连接池
compile "com.alibaba:druid:1.0.12"
//json
compile "com.google.code.gson:gson:2.2.4"
//log4j
compile "log4j:log4j:1.2.17"
}
}
2、配置各项目之间的依赖
entity依赖于common
dao依赖于entity
service依赖于dao
controller依赖于service
到此,项目之间的依赖关系处理完毕
四、创建包结构
这太简单了,不说了
五、导入配置文件
web.xml
springmvc
application
mybatis
mybatis映射文件
*.properties
六、使用gradle刷新项目,把jar都引入进来
七、部署启动项目
访问结果如下:
看到这个温馨的页面,恭喜你,大功告成!!!