MyBatis中列名和属性名不一致的两种解决方法

使用resultMap

该方式的详细用法见封装MyBatis输出结果那一篇博客。

使用列别名

resultType的默认原则是:同名的列值赋值给同名的属性

这个时候可以从sql语句下手,使用列别名,这里面的列别名和java对象中的属性名一致

<select id="selectAlias" resultMap="com.itheima.domain.User">
    select id as myid,username as myname from user 
</select>

猜你喜欢

转载自blog.csdn.net/kidchildcsdn/article/details/114167437