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>作为根节点,在根节点中支持 ...
随机推荐
- iOS UIWebView清除缓存
UIWebView清除Cookie: //清除cookies NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieSto ...
- 楼市、股市后下一届ZF将用什么去做超发货币的蓄水池(
这是天涯论坛上最近的的一个热帖合集,周小川曾直言超发货币需要蓄水池来装,以控制通货膨胀.这个蓄水池楼市做过.股市曾经也充当过,或许现在的地下钱庄也算一部分吧,那下一届政府会如何选择这个蓄水池呢,这或将 ...
- AWK只打印某个域后的所有域
如转载请指明(博客http: yangzhigang cublog cn).前言:有时我们需要将某个域之后的所有域打印出来,而且每个记录(行)的域的个数也不一定,所以用$4,$5,… $n,… $(N ...
- xp系统的安装SVN
xp系统安装SVN,出现错误: 解决办法: 1,首先确定xp体统是否为sp3,SVN安装需要在sp3以上: 2,检查windows Installer是否开启,解决:控制面板-管理工具-服务—wind ...
- Android 用Animation-list实现逐帧动画
第一步:先上图片素材,以下素材放到res/drawable目录下: http://blog.csdn.net/aminfo/article/details/7847761 图片素材: 文件名称: ic ...
- 第十一篇 Integration Services:日志记录
本篇文章是Integration Services系列的第十一篇,详细内容请参考原文. 简介在前一篇,我们讨论了事件行为.我们分享了操纵事件冒泡默认行为的方法,介绍了父子模式.在这一篇,我们会配置SS ...
- WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform
参看:http://www.secdoctor.com/html/yyjs/31101.html
- jsp上传excel文件并导入数据库
1,excel文件的上传 需要借助jar包:commons-fileupload-1.2.1.jar以及commons-io-1.3.2.jar 前端的html文件 <form id=" ...
- CNContact对通讯录的基本使用(增删改查)
/** * 注意:iOS9才有能使用 * 首先在工程里导入ContactsUI.framework和Contacts.framework两个框架 * * * 源代码的链接地址 * 链接: http:/ ...
- Android 开发环境搭建以及编译
两种搭建编译环境的方式,一种方法是用户安装虚拟机,然后安装基础的Ubuntu12.04.2 系统,利用提供的工具和详细的使用步骤,搭建编译环境:另外一种方法是用户安装虚拟机,然后直接加载 “搭建好的U ...