1.MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMap。

也只有在mapper的select标签中,才会指定resultMap属性的值,其他insert/update/delete是不需要指定resultsMap属性的。

mapper文件里还有一个重要属性,parameterType。指定参数的类型

<select id="selectBlog" parameterType="int" resultType="Blog">
select * from t_blog where id = #{id}
</select><!--来自SQL映射文件BlogMapper.xml-->

resultMap就是进行object与table记录的转换的啊。

3. MyBatis是基于“数据库结构不可控”的思想建立的,也就是我们希望数据库遵循第三范式或BCNF,但实际事与愿违,那么结果集映射就是MyBatis为我们提供这种理想与现实间转换的手段了,而resultMap就是结果集映射的配置标签了。

resultMap就是结果映射标签

resultMap就是结果映射标签!

resultMap就是结果映射标签!!

所以resultMap要指定两边的具体值啊。即:指定

<select id="selectOne" resultMap="BaseResultMap">
select * from tbl_user
<where>
<trim prefixOverrides="and">
<if test="openid != null">
and openid = #{openid}
</if>
<if test="uid != null">
and uid = #{uid}
</if>
<if test="phone != null">
and phone = #{phone}
</if>
</trim>
</where>
limit
</select>

即只有查询时候才会得到数据,才会用到类型匹配转换,insert/update/delete等这种写操作是不会用到resultmap/resulttype类型转换的。

2.resultmap也可以进行继承的,从其他resultmap里继承过来匹配的关系

<resultMap id="BaseResultMap" type="User" extends="SimpleResultMap">
<id property="uid" column="uid" /> <result property="unionid" column="unionid"/>
<result property="openid" column="openid"/>
<result property="age" column="age"/>
<result property="birthday" column="birthday"/>
<result property="sex" column="sex"/>
<result property="phone" column="phone"/>
<result property="email" column="email"/>
<result property="qq" column="qq"/>
<result property="wechat" column="wechat"/>
<result property="province" column="province"/>
<result property="city" column="city"/>
<result property="country" column="country"/>
<result property="channel" column="channel"/>
<result property="password" column="password"/> <!-- SimpleResultMap 中已经有
<result property="nickname" column="nickname"/>
<result property="headimgurl" column="headimgurl"/>
<result property="appid" column="appid"/>
<result property="password" column="password"/>
-->
<result property="backgroundimg" column="backgroundimg"/>
<result property="description" column="description"/>
<result property="createTime" column="create_time"/> </resultMap> <resultMap id="SimpleResultMap" type="User">
<id property="uid" column="uid" />
<result property="nickname" column="nickname"/>
<result property="headimgurl" column="headimgurl"/>
</resultMap>

最新文章

  1. three.js加载obj模型
  2. WinForm 窗体应用程序(进阶)之一
  3. 丰富Easyui 的插件 - lookup
  4. Mysql denied for user &#39;odbc@localhost&#39; || denied for user &#39;root@localhost&#39;
  5. 创建Spring容器
  6. keepalived安装配置(nginx)
  7. jvisualvm 使用
  8. 使用JUnit4与JMockit进行打桩测试
  9. puppet任务计划
  10. layui框架部分功能介绍
  11. MySQL数据库“十宗罪”(十大经典错误案例)
  12. Zabbix监控IO
  13. angular4.0快速import依赖路径
  14. 按月分表(create table)
  15. 又到毕业季,尚学堂喊你免费领取100个Java毕设项目(含源码视频),限时一周哦!
  16. Codeforces 1077D Cutting Out(二分答案)
  17. Mac OS X 绑定80端口,不装nginx的小技巧
  18. vue axios跨域
  19. pjsip 播放音视频
  20. webassembly

热门文章

  1. java synchronized(object/this)的 区别
  2. 掌握Spark机器学习库-08.2-朴素贝叶斯算法
  3. 添加QScintilla时显示无法解析的外部函数
  4. 获取汉字的拼音首字母--pinyin
  5. 服务器中打开IIS管理器
  6. 将java project打包成jar包,web project 打包成war包的几种演示 此博文包含图片
  7. 通过JS判断联网类型和连接状态的实现代码
  8. BZOJ 3158 千钧一发 最小割
  9. (error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on d
  10. php扩展1:filp/whoops(用于调试,方便定位错误点)