iBATIS Spring Struts2整合实例浅析
上篇iBATIS + Spring整合例子,今天补充一个新Spring + iBATIS整合的方式 ,这种方式使通过Spring注入SqlMapClientTemplate完成的。具体模式如下:
/* * UserDAOImpl3.java */ package net.chinaideal.samples.ibatis.dao; import org.springframework.orm.ibatis.SqlMapClientTemplate; import net.chinaideal.samples.ibatis.model.User; /** * SpringiBatis - UserDAOImpl3.java * ---------------------------------------------- * @version 0.1 2007-1-23 * @author Panglei(bj02267) * ---------------------------------------------- * 说明: * 整合可以将Spring的iBatis的SqlMapClientTemplate单独注入 */ public class UserDAOImpl3 implements UserDAO { private static final long serialVersionUID = -6615310540042830594L; //iBatis SqlMapClientTemplate protected SqlMapClientTemplate sqlMapClientTemplate; /* (non-Javadoc) * @see net.chinaideal.samples.ibatis.dao.UserDAO#getUserByUsername(java.lang.String) */ public User getUserByUsername(String username) { return (User) sqlMapClientTemplate.queryForObject("getUserbyUsername", username); } public SqlMapClientTemplate getSqlMapClientTemplate() { return sqlMapClientTemplate; } public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) { this.sqlMapClientTemplate = sqlMapClientTemplate; } }
applicationContext.xml文件:
!-- Spring iBatis SqlMapClient -- bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean" property name="configLocation" value="/WEB-INF/sqlmap-config.xml"/ property name="dataSource" ref="dataSource"/ /bean !-- Spring iBatisTemplate -- bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate" property name="sqlMapClient" ref bean="sqlMapClient"/ /property /bean !-- UserDAO方案三 -- bean id="userDAO3" class="net.chinaideal.samples.ibatis.dao.UserDAOImpl3" property name="sqlMapClientTemplate" ref bean="sqlMapClientTemplate"/ /property /bean
相关推荐
Dullonjiang 2020-01-23
与卿画眉共浮生 2011-06-25
yierxiansheng 2014-06-18
登峰小蚁 2019-12-24
plane 2017-10-19
踩风火轮的乌龟 2019-10-23
pandapanda 2014-05-08
阿泰 2014-07-02
shouen 2016-04-26
whileinsist 2012-04-07
spprogrammer 2018-01-25
Coohx 2017-12-05
AndroidOliver 2012-05-14
BruceWayne 2014-12-02
liubang000 2014-05-30
KOJ 2013-11-26
CXC0 2013-08-28