使用resulttype进行结果映射时,查询的列名和映射的pojo属性名完全一致,该列才能映射成功。
如果查询的列名和映射的pojo属性名全部不一致,则不会创建pojo对象;
如果查询的列名和映射的pojo属性名有一个一致,就会创建pojo对象。
<select id="findorderextbyid" parametertype="int" resulttype="com.ahd.model.orderext"> select o.*,u.username,u.address from `user` u,orders o where u.id=o.user_id and u.id=#{id} </select>
当输出结果只有一列时,可以使用resulttype指定简单类型作为输出结果类型。
(解释:输出的为count…和查询内容无关的,可以使用resulttype)
如果查询出来的列名和属性名不一致,通过定义一个resultmap将列名和pojo属性名之间作一个映射关系。
1、 定义resultmap
2、 使用resultmap作为statement的输出映射类型
<resultmap id="userbyresultmap" type="user"> <id property="id" column="id_"></id> <result property="username" column="username_"></result> <result property="birthday" column="birthday_"></result> <result property="sex" column="sex_"></result> <result property="address" column="address_"></result> </resultmap> <select id="finduserbyresultmap" parametertype="userqueryvo" resultmap="userbyresultmap"> select id id_, username username_, birthday birthday_, sex sex_, address address_ from user where username like "%${user.username}%" </select>
如对本文有疑问, 点击进行留言回复!!
Algebra:Chapter 0 - 预备知识: 集合论和categories
springboot + vue上传图片在服务器并实现在线预览
请谨慎使用增强for循环,刚接触Java值得一看(手动狗头)
【Nginx】还不会使用Nginx解决跨域问题?肝这一篇就够了!!
网友评论