Spring+SpringMVC +MyBatis整合配置文件案例66666
Spring+SpringMVC +MyBatis整合配置文件案例
![](http://static.blog.csdn.net/images/category_icon.jpg)
![](http://static.blog.csdn.net/images/arrow_triangle%20_down.jpg)
版权声明:本文为博主原创文章,未经博主允许不得转载。
目录(?)[+]
Spring+SpringMVC +MyBatis整合配置文件案例
针对spring/SpringMVC/MyBatis三个框架的整合有很多的方式,经过最近的学习我来总结一下其配置文件的设置以及三大框架之间的一些关系.代码配置后面附上,仅作为建议.
三大框架之间的关系图如下:
配置文件配置的对应关系:
1.Spring配置文件
applicationContext.xml
<context:component-scan base-package="service"/> <context:property-placeholder location="classpath:/c3p0.properties"/><!-- 注册数据库的资源 --> <bean id="dataSource" class = "com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value = "${c3p0.driver}"></property><property name="jdbcUrl" value = "${c3p0.url}"></property><property name="user" value = "${c3p0.user}"></property><property name="password" value = "${c3p0.password}"></property> </bean><!-- 声明式的事务处理 --> <bean id = "transactionManager" class = "org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="datasource"></property> </bean><!-- 创建通知 配置切面和切入点--> <tx:advice id="advice"><tx:attributes><tx:method name="add*" propagation="REQUIRED" /><tx:method name="del*" propagation="REQUIRED" /><tx:method name="update*" propagation="REQUIRED" /><tx:method name="find*" propagation="SUPPORTS" read-only="true" /><tx:method name="*" read-only="true" /></tx:attributes> </tx:advice><aop:config ><aop:pointcut expression="execution(* servlet..*.*(..))" id="pc"/><aop:advisor advice-ref="advice" pointcut-ref="pc"/> </aop:config><!-- 整合MyBatis --> <bean id = "SqlSessionFactory" class = "org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref = "dataSource"></property><!-- 导入核心配置文件 --><property name="configLocation" value = "classpath:/sqlMapConfig.xml"></property><!-- 导入映射文件 --><property name="mapperLocations" value = "classpath:/pojo/*.xml"></property> </bean><!-- spring为mapper接口创建代理对象 --> <bean class = "org.mybatis.spring.mapper.MapperScannerConfigurer" ><property name="basePackage" value = "mapper"></property> </bean>
2.SpringMVC配置文件
applicationContext-mvc.xml
1. <!-- 开启mvc注解 --> <mvc:annotation-driven /> <context:component-scan base-package="controller"></context:component-scan> 2. <!-- 内部资源视图管理器 --> <bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/"></property><property name="suffix" value = ".jsp"></property> </bean>
3.MyBatis配置文件
sqlMapConfig.xml
1. MyBatis核心配置文件 <configuration><!-- 可以设置其缓存和其他一些事务--> </configuration>
UserMapper.xml
<mapper namespace="mapper.UserMapper"><!-- 映射配置文件指定开启二级缓存 --> <cache/><!-- 复用sql语句 --> <sql id="selectUser"> select * from user </sql><select id="findAll" resultType="pojo.User"><include refid="selectUser"/> </select>
4.web.xml配置文件
web.xml
1. <!--配置过滤器--> <filter><filter-name>filter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param><param-name>Encoding</param-name><param-value>UTF-8</param-value> </init-param> </filter><filter-mapping><filter-name>filter</filter-name><url-pattern>/*</url-pattern> </filter-mapping> <servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:/applicationContext*.xml</param-value></init-param> </servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>*.action</url-pattern> </servlet-mapping>
不太善于言辞,希望得到大家的支持,谢谢!
写于2017/04/13
转载于:https://www.cnblogs.com/zftxdh/p/7086501.html
Spring+SpringMVC +MyBatis整合配置文件案例66666相关推荐
- Spring+SpringMVC+MyBatis整合教程
2019独角兽企业重金招聘Python工程师标准>>> 1.基本概念 1.1.Spring Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框 ...
- SSM整合——Spring+SpringMVC+MyBatis整合
文章目录 1. 数据库环境 2. 项目基本结构搭建 3. 配置MyBatis 4. 配置Spring 5. 配置SpringMVC 6. Controller和视图层编写 7. 配置Tomcat,进行 ...
- Spring+SpringMVC+Mybatis整合【L】
我喜欢直接上代码,这里做个解说,代码下载 http://download.csdn.net/detail/q260996583/9905047 项目框架图: 1.pom.xml 文件内容 <pr ...
- Spring+SpringMVC+MyBatis整合基础篇
基础篇 Spring+SpringMVC+MyBatis+easyUI整合基础篇(一)项目简介 Spring+SpringMVC+MyBatis+easyUI整合基础篇(二)牛刀小试 Spring+S ...
- Spring+SpringMVC+Mybatis整合
一.简单测试工程搭建 1.Mybatis所需要的的jar包(包含数据库驱动包和相关的日志包).SpringMVC和Spring的jar包 2.然后构建一个基本的工程,这里我们使用mapper代理的方式 ...
- springmvc教程--整合mybatis开发(spring+springMVC+mybatis整合开发)
一.整合mybatis 为了更好的学习 springmvc和mybatis整合开发的方法,需要将springmvc和mybatis进行整合. 整合目标:控制层采用springmvc.持久层使用myba ...
- Eclipse中 搭建 Spring+SpringMVC+Mybatis整合(下)
通过前面的步骤可以搭建好 Maven 以及下载依赖框架,那么接下来就是编写框架的配置文件了,配置分为以下三个步骤: 配置 SpringMVC 配置 Mybatis 配置 log 以下配置 Spring ...
- Spring+SpringMVC+Mybatis 整合入门
文章目录 整体结构 结构图 Spring 整合SpringMVC web.xml SpringMvc.xml Spring整合Mybatis applicationContext.xml 代理接口的配 ...
- 【Spring】Spring SpringMVC MyBatis 整合 applicationContext.xml文件笔记
今天主要记录在SSM整合 主要的配置文件代码内容: <?xml version="1.0" encoding="UTF-8"?><beans ...
最新文章
- kettle获取当前日期_kettle中通过 时间戳(timestamp)方式 来实现数据库的增量同步操作(一)...
- 如何去除小数点后面多余的0_704密封胶如何使用?怎么样去除多余的704密封胶?...
- 【学习笔记】供应链金融简介(精华)
- MySQL建表添加乐观锁字段_Java秒杀系统优化-Redis缓存-分布式session-RabbitMQ异步下单-页面静态化...
- 初识JS-基础中的基础
- python零基础学习书-Python零基础到进阶必读的书藉:Python学习手册pdf免费下载
- Atitit.软件GUI按钮与仪表盘(01)--报警系统--
- App 上架 AppStore和证书的各种区别
- Linux操作命令分类详解 - 目录文件(二)
- 分割视频的方法有哪些?
- Codeforces Round 862 (Div. 2) 题解
- 收藏:什么是PACD工作法
- 赋诗一首!——《秋》
- RabbitMQ的基础应用
- numpy中的协方差,方差相关计算
- pfn_to_page
- 海康威视嵌入式软件开发工程师笔试+面试经历【已拿offer】
- 如何保障测试用例的覆盖率
- 2009最新雷人语录
- 计算机水平用什么形容词形容,形容应用价值的词语有哪些 , 形容价值的成语有哪些...
热门文章
- kube-controller-manager 配置参数解读
- k8s部署mysql集群(statefulset):主写从读、一主多从集群
- python3数据类型:Tuple(元组)
- C++11 Lambda表达式(匿名函数)详解
- 无偏估计【统计学-通俗解释】
- bit、byte、位、字节、汉字、字符之间的区别
- html div阴影向上,css3阴影向上缓动样式
- 微信红包数字变化动态图片_11.11早安暖心祝福动态图片 微信朋友圈早晨问候语...
- oracle+olh+hive,hadoop+hive+hbase的简单安装 | YallonKing
- 鼠标右键转圈圈_鼠标右键文件夹出现转圈圈假死机情况