Spring整合Mybatis
来源:互联网 发布:把网站生成app源码 编辑:程序博客网 时间:2024/06/17 21:20
Spring整合Mybatis方式有很多种,下面举例其中一种方式:
1、首先需要导入整合jar包(如:mybatis-spring-1.3.0)
2、配置sping-mybatis.xml文件(名称自定义)
<!-- 读取properties文件 --> <bean id="" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:db.properties"></property> </bean>
<!-- 配置数据源 --> <bean id="jdbcDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${driver}"></property> <property name="url" value="${url}"></property> <property name="username" value="${userName}"></property> <property name="password" value="${password}"></property> </bean>
<!-- 实例SqlSessionFactoryBean --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="jdbcDataSource"></property> <property name="mapperLocations" value="classpath:com/bd/dao/impl/*.xml"></property> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.bd.dao"></property> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean>
以上配置为spring中的配置,配置完后需要在web.xml进行配置
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mybatis.xml</param-value> </context-param> <!-- 配置监听 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 清除监听防止内存溢出 --> <listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener>
注意:如何需要整合SpringMVC 需要配置SpringMVC
0 0
- Mybatis -- Mybatis整合Spring
- 【Mybatis】Mybatis整合spring
- 【Spring+Mybatis】Spring整合Mybatis
- MyBatis-----2、MyBatis整合Spring
- Spring整合Mybatis
- spring整合myBatis
- MyBatis-Spring框架整合
- MyBatis+Spring整合示例
- MyBatis+Spring整合示例
- MyBatis+Spring整合方案
- spring + struts2 + mybatis整合
- Spring整合Mybatis
- Mybatis整合Spring
- Spring Mybatis 整合
- spring整合MyBatis
- Mybatis整合Spring
- MyBatis+Spring整合示例
- maven+spring+mybatis整合
- 机器人要多少传感器才能做到如人类般灵敏?
- 一个小妙招能让你在服装上省下好多rmb
- less学习笔记
- robotium真机调试出现Installation failed due to invalid APK file!错误的解决办法
- RabbitMQ和kafka从几个角度简单的对比
- Spring整合Mybatis
- ASN.1探索 - 2 基础知识(1)
- 【学校OJ】二分图匹配 骑士共存问题
- 过了太久我已经不记得这个是啥玩意了,隐约觉得第二第三题方法都太笨了
- C语言基础练习题c语言试题100道(前三十道)
- 数据库关键字
- Angular4学习笔记(四):service
- 菜鸟始终不明白互斥对象和 WaitForSingleObject!
- hud 2084