mybatis spring配置SqlSessionTemplate使用
来源:互联网 发布:显卡满载测试软件 编辑:程序博客网 时间:2024/06/05 09:09
1.application.xml配置
2.MyBatisDAO :
3.mybatis配置文件
4.具体DAO配置
<?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:dwr="http://www.directwebremoting.org/schema/spring-dwr"xmlns:lang="http://www.springframework.org/schema/lang"xmlns:top="http://www.comtop.org/schema/spring-top"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.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.2.xsd http://www.comtop.org/schema/spring-top http://www.comtop.org/schema/top/spring-top.xsd"><!-- spring 注解 --> <context:component-scan base-package="com.dwr"/> <!-- 这句的作用是表示允许DWR访问Spring的Context --> <dwr:annotation-config id="dwr_as"/> <!-- 扫描加了注解@RemoteProxy & @RemoteMethod 的对象 --> <dwr:annotation-scan scanRemoteProxy="false" base-package="com.dwr" /> <!-- dwr初始化配置 --> <dwr:configuration></dwr:configuration> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@10.10.15.29:1521:xxxx" /> <property name="username" value="edmp" /> <property name="password" value="edmp" /> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /><property name="mapperLocations" value="classpath:com/mybatis/*.xml" /> </bean> <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"><property name="sqlSessionFactory" ref="sqlSessionFactory" /></bean><import resource="RESTful.xml" /></beans>
2.MyBatisDAO :
package com.dwr;import java.util.List;import javax.annotation.Resource;import org.apache.ibatis.session.RowBounds;import org.mybatis.spring.SqlSessionTemplate;import org.springframework.stereotype.Repository;@Repositorypublic class MyBatisDAO{@Resource private SqlSessionTemplate sqlSessionTemplate; public MyBatisDAO() { } public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) { this.sqlSessionTemplate = sqlSessionTemplate; } public void delete(String statementId, Object deleteObject) { try { this.sqlSessionTemplate.delete(statementId, deleteObject); } catch (Exception e) { } } public void insert(String statementId, Object insertObject) { try { this.sqlSessionTemplate.insert(statementId, insertObject); } catch (Exception e) { } } public void update(String statementId, Object updateObject) { try { this.sqlSessionTemplate.update(statementId, updateObject); } catch (Exception e) { } } public Object getObject(String statementId, Object selectParamObject) { return this.sqlSessionTemplate .selectOne(statementId, selectParamObject); } @SuppressWarnings("all") public List queryList(String statementId, Object queryParamObject) { return this.sqlSessionTemplate .selectList(statementId, queryParamObject); } @SuppressWarnings("all") public List queryList(String statementId, Object queryParamObject, int pageNo, int pageSize) { RowBounds objRowBounds; int iOffset = (pageNo - 1) * pageSize; objRowBounds = new RowBounds(iOffset, pageSize); return this.sqlSessionTemplate.selectList(statementId, queryParamObject, objRowBounds); } }
3.mybatis配置文件
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd"><mapper namespace="Test"><select id="queryDataCount"parameterType="com.mybatis.Test"resultType="int">SELECT COUNT(1) FROM INF_CONSUMER T WHERE T.UUID = #{uuid}</select></mapper>
4.具体DAO配置
package com.dwr;import org.springframework.stereotype.Repository;import com.mybatis.Test;@Repositorypublic class TestDAO extends MyBatisDAO {public int getCount(Test test) {return (Integer) this.getObject("Test.queryDataCount", test);}}
0 2
- mybatis spring配置SqlSessionTemplate使用
- spring-mybatis整合-SqlSessionTemplate
- MyBatis-Spring整合 注入SqlSessionTemplate
- 配置spring+mybatis时出现Error creating bean with name 'sqlSessionTemplate‘
- Mybatis(基于SqlSessionTemplate的实现) + Spring 练习实战
- 通过 sqlSessionTemplate 整合 Spring 和 MyBatis 的方法
- mybatis SqlSessionFactoryBean SqlSessionTemplate MapperScannerConfigurer
- Mybatis SqlSessionTemplate 源码解析
- mybatis 中的SqlSessionTemplate 理解
- Mybatis SqlSessionTemplate 源码解析
- Mybatis SqlSessionTemplate 源码解析
- Mybatis SqlSessionTemplate 源码解析
- Mybatis SqlSessionTemplate 源码解析
- Spring Boot配置使用Mybatis
- mybatis中 SqlSessionTemplate的理解
- mybatis中 SqlSessionTemplate的理解
- Spring与mybatis的整合实践之SqlSessionTemplate持久化模板
- Spring与mybatis的整合实践之SqlSessionTemplate持久化模板详解
- 第十七章 工作管理 (job control)
- 第十七章 程序管理
- printf中%p的输出应用
- 第十七章 特殊文件与程序
- http://blog.csdn.net/openglnewbee/article/details/38824139
- mybatis spring配置SqlSessionTemplate使用
- 自动化测试:自动化测试用例设计实例
- 第十七章 SELinux 初探
- window.parent和window.opener区别
- Eclipse 配置maven需要注意的地方
- 单例设计模式
- 软件测试的环境搭建
- java Servlet 实现解析Excel
- MySQL之联结(join)操作类型概念总结