美文网首页
Spring学习之基于Gradle的Idea的Spring mv

Spring学习之基于Gradle的Idea的Spring mv

作者: 北有花开 | 来源:发表于2018-05-21 22:17 被阅读76次

如果我们要使用spring mvc必须添加依赖,以前我们是在项目的pom.xml进行依赖的添加。下面我们看看gradle是如何添加的。

首先我们去maven仓库找到我们需要的依赖包。


QQ截图20180521214345.png
QQ截图20180521214425.png

添加到我们的build.gradle文件里面去。


QQ截图20180521215037.png

格式:compile group: '组织机构' , name: '项目名' , version: '版本号'

简化一下:


QQ截图20180521215419.png

是不是很简洁?

格式:
compile "组织机构:项目名:版本号"

注意简化版是" ",两个点哈。

依赖code:

    compile "org.springframework:spring-core:5.0.6.RELEASE"
    compile "org.springframework:spring-web:5.0.6.RELEASE"
    compile "org.springframework:spring-webmvc:5.0.6.RELEASE"
    compile "org.springframework:spring-aop:5.0.6.RELEASE"
    compile "org.springframework:spring-jdbc:5.0.6.RELEASE"
    compile "org.springframework:spring-context-support:5.0.6.RELEASE"

有没有发现如果有一天我需要改一下版本号,是不是每个都要改一下。是不是很麻烦。是的,我们还可以简化一下。


QQ截图20180521221537.png

code:

ext {
    springVersion = "5.0.6.RELEASE"
}

dependencies {
    testCompile "junit:junit:4.12"
    compile "org.springframework:spring-core:${springVersion}"
    compile "org.springframework:spring-web:${springVersion}"
    compile "org.springframework:spring-webmvc:${springVersion}"
    compile "org.springframework:spring-aop:${springVersion}"
    compile "org.springframework:spring-jdbc:${springVersion}"
    compile "org.springframework:spring-context-support:${springVersion}"
}

相关文章

网友评论

      本文标题:Spring学习之基于Gradle的Idea的Spring mv

      本文链接:https://www.haomeiwen.com/subject/puuthftx.html