java-mybaits-009-mybatis-spring-使用,SqlSessionFactoryBean、事务
一、版本限制 参看地址: http://www.mybatis.org/spring/ 二、使用入门 2.1、pom < dependency > < groupId > org.mybatis </ groupId > < artifactId > mybatis-spring </ artifactId > < version > x.x.x </ version > </ dependency > 2.2、SqlSessionFactoryBean创建 在 Spring 的 XML 配置文件中: < bean id ="sqlSessionFactory" class ="org.mybatis.spring.SqlSessionFactoryBean" > < property name ="dataSource" ref ="dataSource" /> </ bean > 要注意 SqlSessionFactory 需要一个 DataSource(数据源) 。这可以是任意 的 DataSource,配置它就和配置其它 Spring 数据库连接一样。 2.3、数据映射器 假设你定义了一个如下的数据 mapper 接口: public interface UserMapper { @Select( "SELECT * FROM users WHERE id = #