IDEA⽤Maven创建SpringMVC项⽬和配置(XML配置⽅法)IDEA⽤Maven创建SpringMVC项⽬和配置(XML配置⽅法)
⼀个⼈的百度甚是寂寞,最近在写Java后台,⽤Maven创建的SpringMVC项⽬可谓爬了很多的坑,在百度滚了⼀天终于有点眉⽬。⼯具准备:IDEA2018.2.4 Java JDK 1.8
IDEA创建项⽬
1、新建⼀个M aven Project,并且选择webapp原型。
2、如图所⽰,这⾥的GroupId和ArtifactID随意填写。
3、修改⼀下Maven的地址(最好修改⼀下)
4、为了快⼀点创建,我们添加⼀个属性值,如图中亮的所⽰,点右边的加号,name=archetypeCatalog value=internal(⾮必须)
5、剩下的保持默认,完成创建。加载完成的图如图所⽰:
添加pom依赖
1、通过Maven添加SpringMVC所需的jar包,单击“l”打开,添加如下图代码(dependencies标签内):
<!--spring 核⼼包-->
<!-- spring start -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
springmvc常用标签<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>            <version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- spring end -->
<!--mybatis核⼼包-->
<dependency>
<groupId&batis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<!--j2ee相关包 servlet、jsp、jstl-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<version>1.2</version>
</dependency>
<!--mybatis/spring 包-->
<dependency>
<groupId&batis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
<!--MySQL 驱动包-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
在Properties标签内添加如下图代码:
<!--spring 版本号-->
<spring.version>3.2.4.RELEASE</spring.version>
<!--mybatis 版本号-->
<mybatis.version>3.2.4</mybatis.version>
<!--log4j ⽇志⽂件管理包⽂件-->
<slf4j.version>1.6.6</slf4j.version>
<log4j.version>1.2.9</log4j.version>
这样就在项⽬中完成了SpringMVC和Mybatis的⽀持。
为了在后续调试过程中⽅便输⼊⽇志,建议⼤家添加log4j的⽇志相关依赖包,代码如下(dependencies标签内):
<!--⽇志⽂件管理包-->
<!--log start-->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.0</version>
</dependency>
<!--log end-->
⼀旦你复制过去之后,Maven就会开始下载相应的jar⽂件,等待下载完成即可。
添加框架⽀持

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。