日期:2014-05-20  浏览次数:20715 次

spring结合 mybatis怎么用呀
配置文件如下
1 spring配置文件
<context:property-placeholder location="classpath:mysql.properties" />  
  
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
  <property name="driverClassName" value="${jdbc.driverClassName}" />  
  <property name="url" value="${jdbc.url}" />  
</bean>  
  
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
  <property name="dataSource" ref="dataSource" />  
</bean>  
  
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
  <property name="configLocation" value="classpath:mybatis-config.xml" />  
  <property name="dataSource" ref="dataSource" />  
</bean>  
  
<!— mapper bean -->  
<bean id="studentMapper" class="org.mybatis.spring.MapperFactoryBean">  
  <property name="mapperInterface" value="com.manager.data.StudentMapper" />  
  <property name="sqlSessionFactory" ref="sqlSessionFactory" />  
</bean>  
2 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>  
  <mappers>  
  <mapper resource="com/manager/data/maps/StudentMapper.xml" />  
  </mappers>  
</configuration>  
 
3 mapper配置文件
<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">  
<mapper namespace="com.manager.data.StudentMapper">  
   
  <!-- 查询学生,根据id -->  
  <select id="getStudent" parameterType="String" resultType="StudentEntity" resultMap="studentResultMap">  
  <![CDATA[  
  SELECT * from STUDENT_TBL ST  
  WHERE ST.STUDENT_ID = #{studentID}  
  ]]>  
  </select>  
   
</mapper>  


文件配置完了,不会调用,帮帮忙

------解决方案--------------------
晕 你找个最简单的例子看下就好了