[框架整合]spring+springmvc+mybatis(1)
程序员文章站
2022-05-23 19:51:36
...
引用于慕课网的一系列课程 Spring+SpringMVC+MyBatis整合参考视频
很优美很规范的整合版本,视频中有很多思想在里面!小伙伴点进去学习吧~
想要源代码的朋友点击这里下载哦~~
写这篇博客是为了加深学习的印象,在整合的过程中遇到什么问题,欢迎留言。
整合顺序
- 搭建项目,导入jar包。(这里我使用maven搭建,也可以自己导入)
- 先整合Mybatis和Spring
(关键配置文件有mybatis-config.xml, spring-dao.xml, spring-service.xml) - 再整合SpringMVC
(关键配置文件有 spring-web.xml, web.xml) - 最后集成测试
那么来吧!
博主maven环境已经搭建好了。
还没搭建好的小伙伴可以点击此处学习
cmd执行命令创建项目seckill
mvn archetype:generate -DgroupId=org.seckill -DartifactId=seckill -DarchetypeArtifactId=maven-archetype-webapp -DarchetypeCatalog=local
编写jar包依赖 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.seckill</groupId>
<artifactId>seckill</artifactId>
<packaging>war</packaging>
<version>1</version>
<name>seckill Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- 使用junit4,因为4可以使用注解的方式单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- 补全依赖 -->
<!-- 1:日志; java日志:slf4j,log4j,logback,common-logging slf4j接口/规范 log4j,logback,common-logging,实现 此处使用slf4j+logback -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.1</version>
</dependency>
<!-- 实现slf4j日志 -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.1</version>
</dependency>
<!-- 2:数据库相关依赖 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.37</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<!-- Dao框架- MyBatis依赖 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.3.0</version>
</dependency>
<!-- mybatis自身实现的spring整合依赖 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.3</version>
</dependency>
<!--3: Servlet web 相关依赖 -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.4</version>
</dependency>
<!-- 4: spring 依赖 -->
<!-- 1)spring核心依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<!-- 2)spring dao层依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<!-- 3)spring web依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<!-- 4)spring test依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<!-- redis 客户端 Jedis-->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.2</version>
</dependency>
<!-- 高效率 的序列化jar [protostuff] -->
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
<version>1.0.8</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-runtime</artifactId>
<version>1.0.8</version>
</dependency>
<!-- Map 工具类 -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2</version>
</dependency>
</dependencies>
<build>
<finalName>seckill</finalName>
</build>
</project>
jar包导入完毕后,创建目录,如下
在下一篇中,将进行整合第二步,整合mybatis+spring。
转载于:https://my.oschina.net/antgan/blog/697216
上一篇: 在云计算的未来Saas该如何发展
下一篇: MyBatis - CRUD操作
推荐阅读
-
ASP.NET Core应用中与第三方IoC/DI框架的整合
-
搭建ssh框架的基本步骤(ssh框架整合实战教程)
-
Win10 19H1新版18290更新大全:日历整合To-Do
-
[翻译].NET Core 3 Preview1和Windows桌面框架开源
-
JS框架之vue.js(深入三:组件1)
-
Spring+Hibernate+Struts(SSH)框架整合实战
-
SpringBoot2.0 整合 Shiro 框架,实现用户权限管理
-
SpringBoot2.0 整合 SpringSecurity 框架,实现用户权限安全管理
-
springboot windows10风格 activiti 整合项目框架源码 shiro 安全框架 druid
-
SSM框架快速整合实例——学生查询