spring配置文件:

<?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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.2.xsd"> <context:property-placeholder location="classpath:application.properties" ignore-unresolvable="true"/>
<util:properties id="fmqProperties" location="classpath:fmq.properties" />
<!--
<context:property-placeholder location="classpath:fmq.properties" ignore-unresolvable="true"/>
--> <bean id="misDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${oracle.jdbc.driverClassName}"></property>
<property name="jdbcUrl" value="${oracle.jdbc.url}"></property>
<property name="user" value="${oracle.jdbc.username}"></property>
<property name="password" value="${oracle.jdbc.password}"></property>
<property name="initialPoolSize" value="10"></property>
<property name="maxPoolSize" value="15"></property>
<property name="maxIdleTime" value="30"></property> <!-- seconds -->
<property name="acquireIncrement" value="5"></property> <!-- increment connections when valid pooled connection size is 0 -->
<property name="idleConnectionTestPeriod" value="60"></property> <!-- test idle connection in pool per 60 seconds -->
</bean> <bean id="misSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="misDataSource" />
<property name="configLocation" value="classpath:MyBatis-Configuration.xml"></property>
</bean> <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="misSessionFactory" />
</bean> <bean id="baseDao" class="com.highershine.gdna2.dao.GdnaBaseDao">
<property name="sqlSessionTemplate" ref="sqlSession"></property>
</bean> <bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="misDataSource"></property>
</bean> <tx:annotation-driven transaction-manager="transactionManager"/> <context:annotation-config />
<context:component-scan base-package="com.highershine.gdna2" /> </beans>

此处Dao继承org.mybatis.spring.support.SqlSessionDaoSupport

import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.util.List; import javax.annotation.Resource; import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository; /**
* <p>
* Dao基类
* </p>
*
*
* @author lizhihua
*
*/
@Repository("baseDao")
public class GdnaBaseDao extends SqlSessionDaoSupport { @Resource
public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){
super.setSqlSessionFactory(sqlSessionFactory);
}
/**
*插入数据
* @param statement
* @return
*/
public int insert(String statement)throws Exception{
return getSqlSession().insert(statement);
} /**
*根据对象插入数据
* @param statement
* @param parameter
* @return
*/
public int insert(String statement, Object parameter) throws Exception{
return getSqlSession().insert(statement, parameter);
}
/**
*删除数据
* @param statement
* @return
*/
public int delete(String statement) throws Exception{
return getSqlSession().delete(statement);
} /**
*根据条件删除数据
* @param statement
* @param parameter
* @return
*/
public int delete(String statement, Object parameter) throws Exception {
return getSqlSession().delete(statement, parameter);
} /**
*更新数据
* @param statement
* @return
*/
public int update(String statement) throws Exception{
return getSqlSession().update(statement);
} /**
*根据条件更新数据
* @param statement
* @param parameter
* @return
*/
public int update(String statement, Object parameter) throws Exception{
return getSqlSession().update(statement, parameter);
} /**
*查询单个实体
* @param <T>
* @param statement
* @return
*/
@SuppressWarnings("unchecked")
public <T> T selectOne(String statement) throws Exception {
return (T) getSqlSession().selectOne(statement);
} /**
*根据条件查询单个实体
* @param <T>
* @param statement
* @param parameter
* @return
*/
@SuppressWarnings("unchecked")
public <T> T selectOne(String statement, Object parameter) throws Exception {
return (T) getSqlSession().selectOne(statement, parameter);
}
/**
*查询列表
* @param <T>
* @param statement
* @return
*/
public <T> List<T> selectList(String statement) throws Exception {
return getSqlSession().selectList(statement);
} /**
*根据条件查询列表
* @param <T>
* @param statement
* @param parameter
* @return
*/
public <T> List<T> selectList(String statement, Object parameter) throws Exception{
return getSqlSession().selectList(statement, parameter);
} /**
*根据条件及分页信息查询列表
* @param <T>
* @param statement
* @param parameter
* @param rowBounds
* @return
*/
public <T> List<T> selectList(String statement, Object parameter,
RowBounds rowBounds) throws Exception{
return getSqlSession().selectList(statement, parameter, rowBounds);
} /**
*创建Blob对象
* @param inputStream
* @return
*/
public Blob createBlob(InputStream inputStream) throws Exception{
if (inputStream == null)
return null; byte[] buffer = new byte[1024];
int readlen = 0;
try {
Blob blob = getSqlSession().getConnection().createBlob();
OutputStream outputStream = blob.setBinaryStream(1); readlen = inputStream.read(buffer, 0, 1024);
while (readlen > 0) {
outputStream.write(buffer, 0, readlen);
outputStream.flush();
readlen = inputStream.read(buffer, 0, 1024);
}
return blob;
} catch (Exception e) {
}
return null;
} }

【配置】Spring和MyBatis整合的更多相关文章

  1. 【Spring 持久层】Spring 与 Mybatis 整合

    持久层整合总述 1.Spring 框架为什么要与持久层技术进行整合? JavaEE开发需要持久层进行数据库的访问操作 JDBC.Hibernate.MyBatis 进行持久开发过程存在大量的代码冗余 ...

  2. Spring+springmvc+Mybatis整合案例 xml配置版(myeclipse)详细版

    Spring+springmvc+Mybatis整合案例 Version:xml版(myeclipse) 文档结构图: 从底层开始做起: 01.配置web.xml文件 <?xml version ...

  3. spring, spring mvc, mybatis整合文件配置详解

    转自:http://www.cnblogs.com/wxisme/p/4924561.html 使用SSM框架做了几个小项目了,感觉还不错是时候总结一下了.先总结一下SSM整合的文件配置.其实具体的用 ...

  4. Spring+springmvc+Mybatis整合案例 annotation版(myeclipse)详细版

    Spring+springmvc+Mybatis整合案例 Version:annotation版 文档结构图: 从底层开始做起: 01.配置web.xml文件 <?xml version=&qu ...

  5. Spring与Mybatis整合的MapperScannerConfigurer处理过程源码分析

    前言 本文将分析mybatis与spring整合的MapperScannerConfigurer的底层原理,之前已经分析过java中实现动态,可以使用jdk自带api和cglib第三方库生成动态代理. ...

  6. Mybatis学习--spring和Mybatis整合

    简介 在前面写测试代码的时候,不管是基于原始dao还是Mapper接口开发都有许多的重复代码,将spring和mybatis整合可以减少这个重复代码,通过spring的模板方法模式,将这些重复的代码进 ...

  7. 九 spring和mybatis整合

    1       spring和mybatis整合 1.1     整合思路 需要spring通过单例方式管理SqlSessionFactory. spring和mybatis整合生成代理对象,使用Sq ...

  8. Mybatis学习(7)spring和mybatis整合

    整合思路: 需要spring通过单例方式管理SqlSessionFactory. spring和mybatis整合生成代理对象,使用SqlSessionFactory创建SqlSession.(spr ...

  9. 框架篇:Spring+SpringMVC+Mybatis整合开发

    前言: 前面我已搭建过ssh框架(http://www.cnblogs.com/xrog/p/6359706.html),然而mybatis表示不服啊. Mybatis:"我抗议!" ...

  10. SpringMVC, Spring和Mybatis整合案例一

    一  准备工作 包括:spring(包括springmvc).mybatis.mybatis-spring整合包.数据库驱动.第三方连接池. 二  整合思路 Dao层: 1.SqlMapConfig. ...

随机推荐

  1. mac 安装 tomcat 配置

    前面的话:记录下 Mac 安装配置 Tomcat 过程 1. 下载安装 Tomcat 下载 Tomcat 地址(官方地址):https://tomcat.apache.org/download-80. ...

  2. PAT甲题题解-1016. Phone Bills (25)-模拟、排序

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789229.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  3. Linux内核学习总结(final)

    Linux内核学习总结 符钰婧 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 ...

  4. Linux内核分析作业 NO.5

    拔掉系统调用的三层皮(下) 于佳心 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-100002900 ...

  5. 【读书笔记】Linux内核设计与实现(第十八章)

    18.1 准备开始 需要: 1.一个确定的bug.但是,大部分bug通常都不是行为可靠定义明确的. 2.一个藏匿bug的内核版本. 18.2 内核中的bug bug发作时的症状: 明白无误的错误代码( ...

  6. 第一章:帝国的余晖 AT&T公司

    启示:自己的想法,有好的技术比什么都重要,一定要注意的是技术,不要贪小便宜,明白自己最先关心的的哪个事情. 书中内容:没有人能活两百岁,也没有公司能辉煌两百年,这就是规律,很难超越.

  7. 微信小程序动画技巧

    用微信小程序自带的wx.createAnimation api可创建动画,该动画效果相比css写的动画更流畅. 栗子与用法,见官网:https://mp.weixin.qq.com/debug/wxa ...

  8. Beta冲刺——day3

    Beta冲刺--day3 作业链接 Beta冲刺随笔集 github地址 团队成员 031602636 许舒玲(队长) 031602237 吴杰婷 031602220 雷博浩 031602134 王龙 ...

  9. spring 默认情况下事务是惟一的 同一个方法里面第一个sql开启后 在执行完 将事务传递给下一个sql

    spring 默认情况下事务是惟一的 同一个方法里面第一个sql开启后 在执行完 将事务传递给下一个sql

  10. 对象内存空间 在创建对象后 运行时 会把对象的方法放到jvm的方法区中 调用时 将方法拿到栈中 执行完后 这个方法会出栈 然后新的方法方法进栈