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>作为根节点,在根节点中支持 ...
随机推荐
- Mybatis在xml文件中处理大于号小于号的方法
第一种方法:用了转义字符把">"和"<"替换掉,然后就没有问题了. AND start_date <= CURRENT_DATE AND en ...
- 【转】C语言中标识符的作用域、命名空间、链接属性、生命周期、存储类型
参考网址:http://blog.csdn.net/zhanglianpin/article/details/41575849 绝对的经典.
- Linux 使用 bg 和 fg 切换任务运行状态
将Linux任务转换到后台执行 平时在运行 Linux 任务时,在任务运行时又想运行其它任务,那么可以把任务切换到后台运行. 使用 ctrl+z 可以把当前的任务转入到后台,这时任务并没有被中止,可使 ...
- WPF--Blend制作Button控件模板
博客园新人,WPF初学者.不涉及理论知识,直接进入操作. 记录一下使用Blend制作Button控件模板过程中,学到Blend几个知识点: 1.渐变画笔编辑器的Alpha选项可以调控件的透明度.即下图 ...
- Java文件操作①——XML文件的读取
一.邂逅XML 文件种类是丰富多彩的,XML作为众多文件类型的一种,经常被用于数据存储和传输.所以XML在现今应用程序中是非常流行的.本文主要讲Java解析和生成XML.用于不同平台.不同设备间的数据 ...
- WordPress 性能检测与速度优化
来源:SayBlog.Me [摘要]在如何提升WordPress性能与速度方面多花一些时间是值得的,本文下面为大家就如何提升WordPress运行效率列出了几点建议以供参考. 你的WordPress博 ...
- 分布式环境下限流方案的实现redis RateLimiter Guava,Token Bucket, Leaky Bucket
业务背景介绍 对于web应用的限流,光看标题,似乎过于抽象,难以理解,那我们还是以具体的某一个应用场景来引入这个话题吧. 在日常生活中,我们肯定收到过不少不少这样的短信,“双11约吗?,千款….”,“ ...
- Fix the “No Private Key” Error Message
This article will show you how to correct the “No Private Key” error message in Windows Internet Inf ...
- MVC ViewModel
ViewModel这个概念不只是在在MVC模式中有,你会在很多关于MVC.MVP.MVVM的文章中见到这个说法,并且这个概念在任何技术中都有可能提到,比如ASP.NET, Silverlight, W ...
- Oracle Flashback Technologies - 估算不同时间段闪回日志的产生量
Oracle Flashback Technologies - 估算不同时间段闪回日志的产生量 v$flashback_database_stat监控闪回数据的i/o开销的统计信息,根据之前的系统负载 ...