spring管理

SqlMapConfig.xml:

    <?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
>
<context:property-placeholder location="classpath:db.properties"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${db.driver}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="url" value="${db.url}"/>
</bean>
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="SqlMapConfig.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="testMapper" class="daoImpl.TestMapperImpl">
<property name="sqlSessionFactory" ref="sessionFactory"/>
</bean>
<!--<bean id="testMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">-->
<!--<property name="mapperInterface" value="mapper.TestMapper"/>-->
<!--<property name="sqlSessionFactory" ref="sessionFactory"/>-->
<!--</bean>--> <!-- Mapper代理的方式开发方式二,扫描包方式配置代理
每个mapper代理对象的id就是类名,首字母小写
-->
<!--<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">-->
<!--<property name="basePackage" value="mapper"/>-->
<!--<property name="sqlSessionFactoryBeanName" value="sessionFactory"/>-->
<!--</bean>-->
</beans>

impl:

    public class TestMapperImpl extends SqlSessionDaoSupport implements TestMapper {
public List<Test> selectByReg() {
return getSqlSession().selectList("selectByReg");
}
}

测试:

    public class SpringTest2 {
@Test
public void test1(){
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/applicationContext.xml");
// TestMapperImpl bean = context.getBean(TestMapperImpl.class);
TestMapper mapper = (TestMapper) context.getBean("testMapper");
List<mapper.Test> list = mapper.selectByReg();
System.out.println(list);
}
}

最新文章

  1. ABP源码分析四十四:ZERO的配置
  2. 利用Microsoft.Practices.Unity的拦截技术,实现.NET中的AOP
  3. iPad开发(Universal Applications)
  4. Android &amp; iOS 第三方 Crash ANR 捕捉上传
  5. POJ 2697 A Board Game(Trie判重+BFS)
  6. 【.net】关于RegexOptions中的各个枚举值的含义
  7. 每天一个linux命令(25):df 命令
  8. net异步线程获取返回值的三种方式
  9. PostgreSQL9.2.4内核源码结构介绍
  10. php字符串截取问题
  11. bzoj4518
  12. I2C操作笔记——以 AT24C04为例
  13. WinSnap屏幕截图 V4.5.6 官方最新版
  14. [Linux] PHP程序员玩转Linux系列-搭建代码开发环境
  15. Python函数之简单总结
  16. [RHEL 7]ISCSI服务端及客户端连接配置
  17. lua_table 学习
  18. fifo 实现问题
  19. Spring-----入门
  20. 重写COMBOXEDIT

热门文章

  1. ProtoBuf 常用序列化/反序列化API 转
  2. 3.python函数编程-reduce函数
  3. Win10系列:VC++媒体播放控制3
  4. IOS应用内支付IAP从零开始详解
  5. 每天CSS学习之!important
  6. bs4 CSS选择器
  7. Flatten Nested List Iterator
  8. freemarker中的null异常处理以及!与??的使用(转)
  9. rnn-nlp-单词预测
  10. asp.net mvc 实现简单的实时消息推送