mybatis手动映射
为什么需要手动映射
当数据表中的列名和pojo中类的属性名不同时,将会出现封装数据失败的现象,MyBatis无法将数据表中的数据准确的封装到pojo对象中,因此必须使用手动映射的方式来实现。
比如 ,java类User 有一项数据为userId ,而在数据库中user表的对应列为user_id,那么就会产生mybatis不能直接对应过去的问题
解决办法 \(\longrightarrow\)手动映射
<mapper namespace="com.kehao.mapper.OrdersMapper">
<select id="queryOrders" resultMap="order">
select * from orders
</select>
<resultMap id="order" type="com.keaho.pojo.Orders">
<id property="id" column="id"></id>
<result property="userId" column="user_id"></result>
<result property="number" column="number"></result>
<result property="createtime" column="createtime"></result>
<result property="note" column="note"></result>
</resultMap>
</mapper>
解释如下:


浙公网安备 33010602011771号