spring与mybati整合方法
(1)spring配置文件:
- <!-- 引入jdbc配置文件 -->
- <context:property-placeholder location="jdbc.properties"/>
- <!--创建jdbc数据源 -->
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
- <property name="driverClassName" value="${driver}"/>
- <property name="url" value="${url}"/>
- <property name="username" value="${username}"/>
- <property name="password" value="${password}"/>
- <property name="initialSize" value="${initialSize}"/>
- <property name="maxActive" value="${maxActive}"/>
- <property name="maxIdle" value="${maxIdle}"/>
- <property name="minIdle" value="${minIdle}"/>
- </bean>
- <!-- 创建SqlSessionFactory,同时指定数据源-->
- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <property name="dataSource" ref="dataSource" />
- </bean>
- <!--创建数据映射器,数据映射器必须为接口-->
- <bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
- <property name="mapperInterface" value="com.xxt.ibatis.dbcp.dao.UserMapper" />
- <property name="sqlSessionFactory" ref="sqlSessionFactory" />
- </bean>
- <bean id="userDaoImpl2" class="com.xxt.ibatis.dbcp.dao.impl.UserDaoImpl2">
- <property name="userMapper" ref="userMapper"/>
- </bean>
- public interface UserMapper {
- @Select("SELECT * FROM user WHERE id = #{userId}")
- User getUser(@Param("userId") long id);
- }
- public interface UserDao {
- public User getUserById(User user);
- }
- public class UserDaoImpl2 implements UserDao {
- private UserMapper userMapper;
- public void setUserMapper(UserMapper userMapper) {
- this.userMapper = userMapper;
- }
- public User getUserById(User user) {
- return userMapper.getUser(user.getId());
- }
- }
spring与mybati整合方法的更多相关文章
- MyBatis 与 Spring 的完美整合方法
MyBaits 整合 Spring MyBatis-Spring 项目 第一步:创建测试工程 第二步:引入依赖 jar 包 第三步:编写 Spring 配置文件 第四步:编写 MyBatis 配置文件 ...
- 你所不知的spring与mybatis整合方法
内容目录 1.采用MapperScannerConfigurer2.采用接口org.apache.ibatis.session.SqlSession的实现类org.mybatis.spring.Sql ...
- spring与mybatis三种整合方法
spring与mybatis三种整合方法 本文主要介绍Spring与Mybatis三种常用整合方法,需要的整合架包是mybatis-spring.jar,可通过链接 http://code.googl ...
- spring与mybatis五种整合方法
1.采用数据映射器(MapperFactoryBean)的方式 不用写mybatis映射文件,采用注解方式提供相应的sql语句和输入参数. (1)Spring配置文件: <!-- 引入jdbc ...
- 轻量级Java EE企业应用实战(第4版):Struts 2+Spring 4+Hibernate整合开发(含CD光盘1张)
轻量级Java EE企业应用实战(第4版):Struts 2+Spring 4+Hibernate整合开发(含CD光盘1张)(国家级奖项获奖作品升级版,四版累计印刷27次发行量超10万册的轻量级Jav ...
- Spring+springmvc+Mybatis整合案例 xml配置版(myeclipse)详细版
Spring+springmvc+Mybatis整合案例 Version:xml版(myeclipse) 文档结构图: 从底层开始做起: 01.配置web.xml文件 <?xml version ...
- Spring与Mybatis整合的MapperScannerConfigurer处理过程源码分析
前言 本文将分析mybatis与spring整合的MapperScannerConfigurer的底层原理,之前已经分析过java中实现动态,可以使用jdk自带api和cglib第三方库生成动态代理. ...
- Mybatis学习--spring和Mybatis整合
简介 在前面写测试代码的时候,不管是基于原始dao还是Mapper接口开发都有许多的重复代码,将spring和mybatis整合可以减少这个重复代码,通过spring的模板方法模式,将这些重复的代码进 ...
- Spring学习6-Spring整合Struts2
一.Spring为什么要整合Struts2 Struts2与Spring进行整合的根本目的就是要让 Spring为Struts2的Action注入所需的资源对象,它们整合的原理则是只要导入了s ...
随机推荐
- 05 linux下编译Memcached
一: linux下编译Memcached(1)先在linux上安装gcc,cmake,autoconf,libtool工具,以后会使用到. 安装命令为:yum install gcc make aut ...
- selenium实现在新窗口打开链接
问题:页面代码中不存在target="_blank",怎么实现点击一个按钮,在新窗口中打开? WebElement link = element.findElement(By.ta ...
- mysql 考勤表异常 【待修改】
有考勤刷卡记录表,表名为attendance ,有如下字段: 姓名 卡号 刷卡时间 刷卡类型 name id time type 张三 59775623 2010-04-01 07:23:37 ...
- 怎样去掉a标签的蓝框
直接上代码 *{-webkit-tap-highlight-color:rgba(255,0,0,0);} 我是直接给每一个都加了这个属性 其实没有必要 因为 只有a 标签 input 标签 和t ...
- 在ListView的GroupItem头中显示每列的Summary
问题描述 WPF自带的ListView和DataGrid控,都提供了数据分组的支持,并可以对分组的Header进行自定义.但是,如果想在每个分组的Header中,显示出本分组的"小计&quo ...
- 简单的积雪shader
// Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject' Shader "Custom/CoverSnow&q ...
- java 中 集合类相关问题
1,Java中Collection和Collections的差别 java.util.Collection 是一个集合接口.它提供了对集合对象进行基本操作的通用接口方法. Collection接口在J ...
- 【BZOJ2422】Times 树状数组
[BZOJ2422]Times Description 小y作为一名资深的dotaer,对视野的控制有着深刻的研究.每个单位在一段特定的时间内会出现在小y的视野内,除此之外的时间都在小y看不到的地方. ...
- mysql存储过程之事务篇
mysql存储过程之事务篇 事务的四大特征: ACID:Atomic(原子性).Consistent(一致性).Isolated(独立性).Durable (持久性) MySQL的事务支持不是绑定在M ...
- apche安装教程
从Apache官网下载windows安装版的Apache服务器了, 现在分享给大家. 1 进入apache服务器官网http://httpd.apache.org/,这里我们以下载稳定版的 htt ...