我是靠谱客的博主 辛勤纸鹤,这篇文章主要介绍mybatis中resultmap和resulttype的区别。,现在分享给大家,希望可以做个参考。

resultType: 当使用resultType做SQL语句返回结果类型处理时,对于SQL语句查询出的字段在相应的pojo中必须有和它相同的字段对应,而resultType中的内容就是pojo在本项目中的位置。
举例:
此时我选择出来的Datainfo整张表就可以对应com.cloud.pojo.Datainfo,的一对一关系。

复制代码
1
2
3
4
5
<select id="selectByUserId" parameterType="java.lang.Integer" resultType="com.cloud.pojo.Datainfo"> select datainfo.* from datainfo,user,collect where datainfo.id=collect.id and collect.user_id=#{userId,jdbcType=INTEGER}; </select>

resultMap: 当使用resultMap做SQL语句返回结果类型处理时,通常需要在mapper.xml中定义resultMap进行pojo和相应表字段的对应。
举例:
此时我使用resultMap,我们需要自己写上边这部分,也就是让表中的列对应实体类的属性。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
<resultMap id="BaseResultMap" type="com.cloud.pojo.Collect"> <id column="collect_id" jdbcType="INTEGER" property="collectId" /> <result column="user_id" jdbcType="INTEGER" property="userId" /> <result column="group_id" jdbcType="INTEGER" property="groupId" /> <result column="id" jdbcType="VARCHAR" property="id" /> </resultMap> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from collect where collect_id = #{collectId,jdbcType=INTEGER} </select>

最后

以上就是辛勤纸鹤最近收集整理的关于mybatis中resultmap和resulttype的区别。的全部内容,更多相关mybatis中resultmap和resulttype内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(62)

评论列表共有 0 条评论

立即
投稿
返回
顶部