mybatis最重要的mapper文件书写
2024-09-05 23:55:51
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>
最新文章
- three.js加载obj模型
- WinForm 窗体应用程序(进阶)之一
- 丰富Easyui 的插件 - lookup
- Mysql denied for user &#39;odbc@localhost&#39; || denied for user &#39;root@localhost&#39;
- 创建Spring容器
- keepalived安装配置(nginx)
- jvisualvm 使用
- 使用JUnit4与JMockit进行打桩测试
- puppet任务计划
- layui框架部分功能介绍
- MySQL数据库“十宗罪”(十大经典错误案例)
- Zabbix监控IO
- angular4.0快速import依赖路径
- 按月分表(create table)
- 又到毕业季,尚学堂喊你免费领取100个Java毕设项目(含源码视频),限时一周哦!
- Codeforces 1077D Cutting Out(二分答案)
- Mac OS X 绑定80端口,不装nginx的小技巧
- vue axios跨域
- pjsip 播放音视频
- webassembly
热门文章
- java synchronized(object/this)的 区别
- 掌握Spark机器学习库-08.2-朴素贝叶斯算法
- 添加QScintilla时显示无法解析的外部函数
- 获取汉字的拼音首字母--pinyin
- 服务器中打开IIS管理器
- 将java project打包成jar包,web project 打包成war包的几种演示 此博文包含图片
- 通过JS判断联网类型和连接状态的实现代码
- BZOJ 3158 千钧一发 最小割
- (error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on d
- php扩展1:filp/whoops(用于调试,方便定位错误点)