解决属性名和字段名不一致的问题

时间:2021-06-20 18:22:57   收藏:0   阅读:0

数据库中的字段
技术图片

public class User{
    private int id;
    private String name;
    private String password;
}

测试查出来password为null

//select id,name,pwd from mybatis.user where id=#{id}

解决办法:

resultMap

结果集映射

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>
评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!