spring3+ ibatis2()配置

参考
http://blog.csdn.net/cl61917380/article/details/6528470

特别说明,spring3对ibatis2的支持 与spring2.5与ibatis2写法不同

一 xml 配置

<!-- 1.第一种方式(必须使用注解的方式@Resource) : 自定义一些方法 如queryForString,queryForBoolean等 -->
<bean id="mySqlMapClientDaoSupport" class="com.jungle.dao.common.MySqlMapClientDaoSupport">
  <property name="dataSource" ref="dataSource" />
  <property name="sqlMapClient" ref="sqlMapClient" />
</bean>

<!-- 2.第二种方式(必须使用注解的方式@Resource),使用get,set方式需要使用接口的方式才行-->
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
  <property name="dataSource" ref="dataSource" />
  <property name="sqlMapClient" ref="sqlMapClient" />
</bean>

</beans>

二 java 写法




UserDaoImpl:

@Component("userDao")
public class UserDaoImpl implements UserDao {
// 使用get,set方式不行 ,因为SqlMapClientTemplate不是接口
@Resource
private SqlMapClientTemplate sqlMapClientTemplate;

@Resource
private MySqlMapClientDaoSupport mySqlMapClientDaoSupport;





UserAction:


public class UserAction extends ActionSupport {
@Resource
private UserDao userDao;

@Override
public String execute() throws Exception {
  System.out.println(userDao.getUser("1"));
  return SUCCESS;
}
}

猜你喜欢

转载自jiakechong.iteye.com/blog/1115557
今日推荐