题主要明白Mybatis的原理,mybatis只是个orm框架,只是在你查询的时候通过映射成想要的对象,但是查询条件里面的字段名必须是数据库里面的字段才可以
那你换成数据库中的字段试试看呢
感谢大佬帮忙,确实如上面两位大佬说的。
不知道你这个问题是否已经解决, 如果还没有解决的话:<?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>