解决字段名与实体类属性名冲突

陌路散爱 提交于 2019-11-29 02:30:21

1.在查询时给字段起别名,让别名和实体类属性名一样

        <!-- 通过id查询 -->

       <select id="selectById" parameterType="int"

              resultType="com.zhiyou100.kfs.bean.Users">

              select id as uid,name uname,age uage from users where id=#{id}

       </select>

 

 

2.通过mybatis的resultMap标签设置对应关系

       <select id="selectById" parameterType="int"

              resultMap="myMap">

              select id,name,age from users where id=#{id}

       </select>

       <resultMap type="com.zhiyou100.kfs.bean.Users" id="myMap">

              <id column="id" property="uid"/>

              <result column="name" property="uname"/>

              <result column="age" property="uage"/>

       </resultMap>

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!