Mybatis——解决属性名和字段名不一致的问题
private int id;
private String name;
private String password;//pwd改为password

测试后pwd变为null
解决方法:
-
起别名
<select id="getUserById" parameterType="int" resultType="com.yl.pojo.User">
select id,name,pwd as password from mybatis.user where id = #{id}
</select> -
resultMap结果集映射
<resultMap id="UserMap" type="User">
<!--colum对应数据库列名 property对应实体类属性-->
<!-- <result column="id" property="id"/>-->
<!-- <result column="name" property="name"/>-->
<result column="pwd" property="password"/>
</resultMap>
<select id="getUserById" parameterType="int" resultMap="UserMap">
select * from mybatis.user where id = #{id}
</select> -
浙公网安备 33010602011771号