Mybatis(四)ResultMap

(1)ResultMap的配置和使用
1、为什么使用ResultMap
结果集(类)中的列名和对象中的属性名称不匹配,解决方案:使用resultMap元素

2、ResultMap属性和子元素
id元素:当前mapper文件中resultMap的唯一名称
type元素:把结果集封装的对象

子元素
id元素:功能和result一样,如果是主键建议使用id元素提升性能
result元素:匹配对象中的哪一属性对应哪一列

3、具体配置

    <resultMap type="User" id="BaseResultMap">
    	<result column="t_id" property="id"/>
    	<result column="t_name" property="name"/>
    	<result column="t_salary" property="salary"/>
    </resultMap>

猜你喜欢

转载自blog.csdn.net/qq_36675851/article/details/89061696