1.mybatis的全局文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-config.dtd">
<configuration>
<settings>
<setting name="lazyLoadingEnabled" value="false"/>
<setting name="aggressiveLazyLoading" value="true"/>
</settings>
</configuration>
2.在spring+mybatis的整合文件中
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis.xml"/>
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:com/you/mapping/*.xml"></property>
</bean>
3.使用
<resultMap id="userMap" type="com.you.pojoexpand.UserExpand">
<id property="id" column="user.id"/>
<result column="id" property="user.id" jdbcType="VARCHAR"/>
<result column="name" property="user.name" jdbcType="VARCHAR"/>
<result column="password" property="user.password" jdbcType="VARCHAR"/>
<result column="age" property="user.age" jdbcType="INTEGER"/>
<association property="money" javaType="com.you.bean.Money" select ="findMoneyInfo" column="id">
</association>
</resultMap>
<select id="userExpand" resultMap="userMap">
SELECT * FROM USER u
</select>
<select id="findMoneyInfo" resultType="com.you.bean.Money">
select * from Money where userId=${value}
</select>