数据库中的字段
public class User{
private int id;
private String name;
private String password;
}
测试查出来password为null
//select id,name,pwd from mybatis.user where id=#{id}
解决办法:
起别名
<select id=\"getUserById\" resultType=\"com.jialidun.pojo.User\">
select id,name,pwd as password from mybatis.user where id=#{id}
</select>
结果集映射
id name pwd
id name password
<resultMap id=\"UserMap\" type=\"User\">
<!--column数据库中的字段,property实体类中的属性-->
<result column=\"id\" property=\"id\"/>
<result column=\"name\" property=\"name\"/>
<result column=\"pwd\" property=\"password\"/>
</resultMap>
<select id=\"getUserById\" resultMap=\"UserMap\">
select id,name,pwd from mybatis.user where id=#{id}
</select>
原文:https://www.cnblogs.com/ipython258/p/14906643.html