不知道你这个问题是否已经解决, 如果还没有解决的话:
- 你可以看下这个问题的回答https://ask.csdn.net/questions/674166
- 除此之外, 这篇博客: Mybatis开发要点-resultType和resultMap的区别?中的 2、Mapper.xml 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:
<?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.mybatis.mapper.TUserMapper">
<resultMap id="UserResultMap" type="TUser" autoMapping="true">
<id column="id" property="id" />
<result column="userName" property="userName"/>
<result column="realName" property="realName" />
<result column="sex" property="sex" />
<result column="mobile" property="mobile" />
<result column="email" property="email" />
<result column="note" property="note" />
<association property="position" javaType="TPosition" columnPrefix="post_">
<id column="id" property="id"/>
<result column="name" property="postName"/>
<result column="note" property="note"/>
</association>
</resultMap>
<select id="selectTestResultMap" resultMap="UserResultMap" >
select
a.id,
userName,
realName,
sex,
mobile,
email,
a.note,
b.id post_id,
b.post_name,
b.note post_note
from t_user a,
t_position b
where a.position_id = b.id
</select>
</mapper>
如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^