解决属性名和字段名不一致的问题
解决方法:
-
起别名
<select id="getUserById" resultType="com.yy.pojo.User"> select id,name,pwd as password from user where id=#{id} </select>
-
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 * from user where id =#{id} </select>
-
resultMap 元素是MyBatis最重要最强大的元素
-
resultMap 的设计思想,对于简单的语句根本不需要配置显式的结果映射,而对于复杂的语句只需要描述它们的关系