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> |