resultMap / resultType
===================resultMap:实体类的属性和通过resultMap映射后的property属性一致
<resultMap id="workerSelect" type="com.eaju.soms.entity.vo.WorkerSelectEntity">
<result column="worker_id" property="workerId" jdbcType="VARCHAR" />
<result column="NAME" property="workerName" jdbcType="VARCHAR" />
<result column="phone" property="workerPhone" jdbcType="VARCHAR" />
</resultMap>
<select id="getSelectWorkers" resultMap="workerSelect">
SELECT t.`worker_id`,t.`name`,t.`phone` FROM t_workers t WHERE t.certification_status = 1 AND t.is_locking = 0 AND t.is_delete = 0 AND t.user_status = 1 AND t.`leader_id`=#{leaderId}
</select>
------------------------------------------resultMap关联两个实体类:<collection>
<resultMap id="userMap" type="org.tedu.cloudnote.entity.User">
<id property="cn_user_id" column="cn_user_id">
<result property="cn_user_name" column="cn_user_name"/>
.................
<!-- 指定books属性装载数据-->
<collection property="books" javaType="java.util.list" ofType="org.tedu.cloudnote.entity.Book">
<id property="cn_notebook_id" column="cn_notebook_id"/>
<result property="cn_user_id" column="cn_user_id"/>
<result property="cn_notebook_type_id" column="cn_notebook_type_id"/>
<result property="cn_notebook_name" column="cn_notebook_name"/>
</collection>
</resultMap>
<select id="findUserAndBooks"
parameterType="string" resultMap="userMap">
select *
from cn_user u
join cn_notebook b
on(u.cn_user_id=b.cn_user_id)
where u.cn_user_id=#{userId}
</select>
-----------------------------entity
public class User implements Serializable
{
private String cn_user_id;
private String cn_user_name;
private String cn_user_password;
private String cn_user_token;
private List<Book> books;
}
----------------------------------------------
<resultMap id="bookMap" type="org.tedu.cloudnote.entity.Book">
<id property="cn_notebook_id" column="cn_notebook_id"/>
<result property="cn_user_id" column="cn_user_id"/>
.....
<!-- 加载user关联属性值 -->
<association property="user"
javaType="org.tedu.cloudnote.entity.User">
<id property="cn_user_id" column="cn_user_id"/>
<result property="cn_user_name" column="cn_user_name"/>
..........................
</association>
</resultMap>
<!-- 提取所有笔记信息 -->
<select id="findAllBooksAndUser" resultMap="bookMap">
select *
from cn_notebook b
join cn_user u
on(b.cn_user_id=u.cn_user_id)
</select>
======================resultType:实体类的属性必须和数据库的字段一致
<select id="findById" parameterType="string"
resultType="org.tedu.cloudnote.entity.Note">
select * from cn_note
where cn_note_id=#{noteId}
</select>
public class Note implements Serializable
{
private String cn_note_id;
private String cn_notebook_id;
private String cn_user_id;
private String cn_note_status_id;
private String cn_note_type_id;
private String cn_note_title;
private String cn_note_body;
private Long cn_note_create_time;
private Long cn_note_last_modify_time;
}
======================insert
<insert id="insertOperateLog" parameterType="com.eaju.soms.entity.TWorkOrderOperateLog">
INSERT INTO t_work_order_operate_log (
operate_log_id,
work_order_id,
operate_id,
operate_status,
operate_display,
remark,
create_time
)
VALUES
(#{operateLogId},#{workOrderId},#{operateId},#{operateStatus},#{operateDisplay},#{remark},#{createTime})
</insert>
====================update
<update id="quitWorkOrder">
UPDATE t_work_order_transform t
SET t.`transform_status` = 'INACTIVE',
t.`update_time` = now()
WHERE t.work_order_owner_id=#{leaderId}
AND t.work_order_id=#{workOrderId}
</update>
---------------------------------------------------entity
public class Book implements Serializable
{ private String cn_notebook_id; private String cn_user_id; private String cn_notebook_type_id; private String cn_notebook_name; private String cn_notebook_desc; private Timestamp cn_notebook_createtime; //追加关联属性,加载User信息 private User user;
}
resultMap / resultType的更多相关文章
- ibatis中的resultClass,parameterClass,resultMap,resultType的使用与区别
parameterClass 是参数类.指定了参数的完整类名(包括包路径).可通过别名避免每次重复书写冗长的类名. resultClass 是结果类, 二.resultClass取值 1.result ...
- Mybatis第七篇【resultMap、resultType、延迟加载】
resultMap 有的时候,我们看别的映射文件,可能看不到以下这么一段代码: <resultMap id="userListResultMap" type="us ...
- 在mybatis中resultMap与resultType的区别
MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMapresultType是直接表示返回类型的,而resultMap则是对外部ResultMa ...
- Mybatis使用时 resultMap与resultType、parameterMap与 parameterType的区别
Map:映射:Type:Java类型 resultMap 与 resultType.parameterMap 与 parameterType的区别在面试的时候被问到的几率非常高,出现的次数到了令人 ...
- 深入浅出Mybatis系列(八)---mapper映射文件配置之select、resultMap
上篇<深入浅出Mybatis系列(七)---mapper映射文件配置之insert.update.delete>介绍了insert.update.delete的用法,本篇将介绍select ...
- 深入浅出Mybatis系列(八)---mapper映射文件配置之select、resultMap good
上篇<深入浅出Mybatis系列(七)---mapper映射文件配置之insert.update.delete>介绍了insert.update.delete的用法,本篇将介绍select ...
- Mybatis-利用resultMap 输出复杂pojo
个:复杂的sql语句查询的数据集的字段和 pojo的字段不相同,需要用到resultMap做一个对应. ---------------- mybatis中使用resultMap完成高级输出结果映射. ...
- Mybatis 系列8-结合源码解析select、resultMap的用法
[Mybatis 系列10-结合源码解析mybatis 执行流程] [Mybatis 系列9-强大的动态sql 语句] [Mybatis 系列8-结合源码解析select.resultMap的用法] ...
- Mybatis中parameterType、resultMap、statementType等等配置详解(标签中基本配置详解)
一.(转自:https://blog.csdn.net/majinggogogo/article/details/72123185) 映射文件是以<mapper>作为根节点,在根节点中支持 ...
随机推荐
- http://blog.csdn.net/qiutongyeluo/article/details/52468081
http://blog.csdn.net/qiutongyeluo/article/details/52468081
- :first与:first-child的区别
说的简单,:first表示单个元素,:fisrt-child表示的多个元素(集合). 如果追求深一点的话, 1.$(:first).css()表示全局或局部全局的第一个,也就是表示单个元素 2.$(: ...
- ionic安装时遇到的minimatch错误
安装提示 npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a Reg ...
- eclipse的快捷键大全
Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加)Ctrl+Alt+↑ 复制当前行到上一行(复制增加)Alt+↓ 当 ...
- you need to upgrade the working copy first
is too old (format 29) to work with client version '1.9.4 (r1740329)' (expects format 31) 2016年09月18 ...
- linux下如何启动/停止/重启mysql:
一.启动方式1.使用linux命令service 启动:service mysqld start2.使用 mysqld 脚本启动:/etc/inint.d/mysqld start3.使用 safe_ ...
- startssl 申请证书,并在Nginx, apache, Tomcat上使用
tomcat: http://blog.csdn.net/buyaore_wo/article/details/5771470 apache: http://blog.mowd.tw/index.ph ...
- [phonegap]安装phonegap
下载nodejs,安装,单nodejs4.0.0 x64编译时,还需要python2.6 or python2.7: 参考怎么安装python2.7: http://jingya ...
- LaTeX 有哪些「新手须知」的内容?
孟晨 ,在 LaTeX 话题下写错 LaTeX 名字的,一律… 陈硕等 137 人赞同 这是个好问题,虽然提问提得很大.不是很好答,权当抛砖引玉了. 天字第一号原则:不要到网上抄代码,尤其是似懂非懂的 ...
- linux 命令之 insmod
man insmod: INSMOD(8) insmod INSMOD(8) NAME insmod - Simple program to insert a module into the Linu ...