Spring、mybaits整合
mybatis.cfg.xml
<!DOCTYPE configuration PUBLIC "-//mybatis.org/DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd" >
<configuration>
<typeAliases>
<package name="com.lovo.sm.beans"></package>
</typeAliases>
</configuration>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<!-- 启动@AspectJ框架的支持,如果你的项目中,
没有使用JAVA代码所写的切面,就不需要配置 -->
<aop:aspectj-autoproxy/>
<!-- 配置自动扫包规则 -->
<context:component-scan base-package="com.lovo.sm">
</context:component-scan>
<!-- 配置数据源 DataSource -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- &在配置文件中代表& -->
<property name="url" value="jdbc:mysql://localhost:3306/mybatis117?useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="lovo"/>
</bean>
<!-- 配置Session工厂 -->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis.cfg.xml"/>
</bean>
<!-- 将Mapper配置文件与Session进行关联 -->
<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.lovo.sm.mapper"/>
<property name="sqlSessionFactory" ref="sqlSessionFactoryBean"></property>
</bean>
<!-- 配置事务管理器 -->
<bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 事务管理方式一,适合于单数据库,使用注解的方式来管理事务
<tx:annotation-driven transaction-manager="dataSourceTransactionManager"/>
-->
<!-- 事务管理方式二,采用springAOP来声明式的处理事务,
声明式就是脱离你的JAVA代码,通常是声明在配置中 -->
<!-- 声明一个通知 -->
<tx:advice id="txAdvice" transaction-manager="dataSourceTransactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" read-only="true"></tx:method>
<tx:method name="save*" propagation="REQUIRED" read-only="false" rollback-for="Exception"></tx:method>
<tx:method name="update*" propagation="REQUIRED" read-only="false" rollback-for="Exception"></tx:method>
<tx:method name="delete*" propagation="REQUIRED" read-only="false" rollback-for="Exception"></tx:method>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"></tx:method>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"></tx:method>
<tx:method name="search*" propagation="SUPPORTS" read-only="true"></tx:method>
</tx:attributes>
</tx:advice>
<!-- 这里是配置AOP事务关联 -->
<aop:config>
<!-- 声明切入点 -->
<aop:pointcut id="serviceMethod" expression="execution(* com.lovo.sm.service.impl.*ServiceImpl.*(..))"></aop:pointcut>
<!-- 将我们定义的通知,交给AOP来关联 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"></aop:advisor>
</aop:config>
</beans>
Spring、mybaits整合的更多相关文章
- 由“单独搭建Mybatis”到“Mybatis与Spring的整合/集成”
在J2EE领域,Hibernate与Mybatis是大家常用的持久层框架,它们各有特点,在持久层框架中处于领导地位. 本文主要介绍Mybatis(对于较小型的系统,特别是报表较多的系统,个人偏向Myb ...
- JAVA springmvc+spring+mybatis整合
一.springmvc---controller spring----service mybatiss---dao pring(包括springmvc).mybatis.mybatis-sprin ...
- Spring Boot 整合 Druid
Spring Boot 整合 Druid 概述 Druid 是阿里巴巴开源平台上的一个项目,整个项目由数据库连接池.插件框架和 SQL 解析器组成.该项目主要是为了扩展 JDBC 的一些限制,可以让程 ...
- 学习spring第五天 mybatis+spring的整合(maven多模块数据查询使用了分页和连接池),以及aop
mybatis+spring的整合: 导入的依赖:1.数据库连接:mysql-connector-java 2.连接池:druid 3.servlet:javax.servlet-api 4.jstl ...
- struts2 spring mybatis 整合(test)
这几天搭了个spring+struts2+mybatis的架子,练练手,顺便熟悉熟悉struts2. 环境:myEclipse10+tomcat7+jdk1.6(1.8的jre报错,所以换成了1.6) ...
- 【Java EE 学习 79 下】【动态SQL】【mybatis和spring的整合】
一.动态SQL 什么是动态SQL,就是在不同的条件下,sql语句不相同的意思,曾经在“酒店会员管理系统”中写过大量的多条件查询,那是在SSH的环境中,所以只能在代码中进行判断,以下是其中一个多条件查询 ...
- 3.springMVC+spring+Mybatis整合Demo(单表的增删该查,这里主要是贴代码,不多解释了)
前面给大家讲了整合的思路和整合的过程,在这里就不在提了,直接把springMVC+spring+Mybatis整合的实例代码(单表的增删改查)贴给大家: 首先是目录结构: 仔细看看这个目录结构:我不详 ...
- spring+websocket整合
java-websocket的搭建非常之容易,没用框架的童鞋可以在这里下载撸主亲自调教好的java-websocket程序: Apach Tomcat 8.0.3+MyEclipse+maven+JD ...
- Hibernate 与 Spring 的整合
刚刚学习了hibernate和Spring的整合,现在来总结一下. 以实现一个功能为例,与大家分享一下整个过程. 需要实现的功能:建立一个Person类,该类包括name,sex,age,birtha ...
- Spring与Struts2整合VS Spring与Spring MVC整合
Spring与Struts2整合,struts.xml在src目录下 1.在web.xml配置监听器 web.xml <!-- 配置Spring的用于初始化ApplicationContext的 ...
随机推荐
- mongodb数据类型
随着web2.0的时代到来,关系型数据库在越来越多的场景下暴漏出许多问题,为了解决这类问题,NoSql数据库应用而生,今天就来说说当下比较主流的NoSql数据库mongodb. 1. 基本数据类型 ...
- 3 分钟轻松搭建 Ruby 项目自动化持续集成
任何事情超过 90 秒就应该自动化,这是程序员的终极打开方式.Automating shapes smarter future. 这是一篇关于 Ruby 项目持续集成的快速指导教程,教大家如何使用 f ...
- fir.im Weekly - 2015 年开发者调查报告
终于一脚迈入了 2016 年.无论你是否准备好,未来已经汹涌扑来-- 新年第一期的 fir.im Weekly 干货颇多,来看一看:) 2015 Developer Survey stackoverf ...
- redis + 主从 + 持久化 + 分片 + 集群 + spring集成
Redis是一个基于内存的数据库,其不仅读写速度快,每秒可以执行大约110000的写操作,81000的读取操作,而且其支持存储字符串,哈希结构,链表,集合丰富的数据类型.所以得到很多开发者的青睐.加之 ...
- PC端和移动端地址适配
判断当前页面的打开方式是pc还是移动设备,如果是移动设备,跳转到对应移到端网站的方法: 方法一.还是用@media screen 思路:css使用媒体查询,当屏幕小于760px时,使某个元素的样式发生 ...
- Enterprise Solution 2.3
1. 登陆窗体和主界面增加语言选项,同时可记住用户登陆的语言和数据库. 2. 主界面的树功能可记住上次打开的模块菜单. 3. 修复主界面菜单生成问题和导航图区上下文菜单生成问题. 4. 增加自动更新功 ...
- 纯CSS实现JS效果研究
利用CSS3:checked选择器和~配合实现tab切换 效果: 代码: <style> body,div,input,label{ margin:0; padding:0; } #tab ...
- KlayGE 4.4中渲染的改进(二):DR的其他改进
转载请注明出处为KlayGE游戏引擎,本文的永久链接为http://www.klayge.org/?p=2749 上一篇讲了TBDR的实现,本篇继续讲解deferred rendering层的一些 ...
- Docker 有什么优势?
1.什么是容器? 依托与linux 内核功能的虚拟化技术 2. docker 是什么? 能够把应用程序自动部署到容器的开源引擎 3. docker 跟原有的工具有何区别? 传统的部署模式是:安装(包管 ...
- php分享(三十六)mysql中关联表更新
一:关联不同的表更新 1: 通过where关联更新 update student s, city c set s.province_name = c.province_name, s.city_nam ...