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>作为根节点,在根节点中支持 ...
随机推荐
- 用JQuery给图片添加鼠标移入移出事件
$("#addLineImg").mouseover( function(){ $("#addLineImg").attr("src",&q ...
- 进度太慢了,扫频仪PCB
实在是画过最纠结的一块PCB,左边布线很轻松,但是右边32芯片用到FSMC,还有很多个引出的IO口,相互交叉纠结在了一起,有几根线一路打了3,4个过孔,实在是难布. 工程查了下是6月17号画原理图的, ...
- JQuery:JQuery捕获HTML
JQuery:捕获HTML1.jQuery - 获取内容和属性介绍: jQuery 拥有可操作 HTML 元素和属性的强大方法. jQuery 中非常重要的部分,就是操作 DOM 的能力. jQuer ...
- mysql 操作日期函数【增加,减少时间】
详情链接:http://www.runoob.com/sql/func-date-add.html 定义和用法 DATE_ADD() 函数向日期添加指定的时间间隔. DATE_ADD(date,INT ...
- Swift vs. Objective-C:未来看好 Swift 的十个理由
Swift vs. Objective-C:未来看好 Swift 的十个理由 是时候使用易入手又全面的Swif语言为iOS和mac OS X做应用开发了. 虽然编程语言不会那么容易消逝,但坚持衰落范例 ...
- 商业智能BI和ERP的融合之路
企业在发展过程中为了更好的跟上同行业的步伐,甚至是为了在众多企业中脱颖而出,他们会主动寻求全面的企业解决方案.但是由于行业的快速发展,需求的不断增长,市面上的智能软件层出不穷,这也给了企业选择的困难. ...
- Oracle RAC 11.2.0.4 – RHRL 6.4: DiskGroup resource are not running on nodes. Database instance may not come up on these nodes
使用DBCA创建新库的时候报错: 查看资源状态: $ crsctl stat res -t ------------------------------------------------------ ...
- oc 正则图片<img /> 标签
-(NSString *)getImageAttributeValue:(NSString *)content attributeKey:(NSString *)key { NSString *reg ...
- 基于jdk proxy的动态代理模式
代理模式 是spring AOP机制的实现基础,有必要学习一下. 有两种,一种是目标类有接口的, 采用JDK动态代理,一种是目标类没接口的,采用CGLIB动态代理. 先看一组代码, package c ...
- Swift游戏实战-跑酷熊猫 05 踩踏平台是怎么炼成的
这节内容我们一起学习下随机长度的踩踏平台的原理是怎么样的. 要点: 平台的组成 我们的平台由3部分组成 左: 中: 右: 其中中间部分是可以无缝衔接的,下面就是两个中间部分衔接在一起 要任何长度的平台 ...