Skip to content

Instantly share code, notes, and snippets.

@safeJar
Created September 21, 2015 01:48
Show Gist options
  • Select an option

  • Save safeJar/78234b77abeb524d0855 to your computer and use it in GitHub Desktop.

Select an option

Save safeJar/78234b77abeb524d0855 to your computer and use it in GitHub Desktop.
mybatis 和 spring 整合的基本配置
/**
1.导入相应的jar包
2.在applicationContext.xml文件中配置相应的bean
3.配置mybatis的配置文件
*/
这段主要是applicationContext.xml的配置
<!-- datasource -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${driverClassName}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="maxActive" value="${maxActive}" />
<property name="maxWait" value="${maxWait}" />
<property name="maxIdle" value="${maxIdle}" />
<property name="validationQuery" value="select 1 from dual" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="true" />
<property name="testOnReturn" value="true" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="/WEB-INF/conf/mybatisConfiguration.xml"></property>
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
<constructor-arg index="1" value="SIMPLE" />
</bean>
--------------------------------------------------------------------------------------------
下面是mybatis 的主要的配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- <settings> -->
<!-- <setting name="cacheEnabled" value="true" /> -->
<!-- </settings> -->
<typeAliases>
<typeAlias type="com.intel.model.home.HomeProduct" alias="homeProduct" />
</typeAliases>
<mappers>
<mapper resource="com/intel/dao/home/HomeMapper.xml" />
</mappers>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment