===================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的更多相关文章

  1. ibatis中的resultClass,parameterClass,resultMap,resultType的使用与区别

    parameterClass 是参数类.指定了参数的完整类名(包括包路径).可通过别名避免每次重复书写冗长的类名. resultClass 是结果类, 二.resultClass取值 1.result ...

  2. Mybatis第七篇【resultMap、resultType、延迟加载】

    resultMap 有的时候,我们看别的映射文件,可能看不到以下这么一段代码: <resultMap id="userListResultMap" type="us ...

  3. 在mybatis中resultMap与resultType的区别

    MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMapresultType是直接表示返回类型的,而resultMap则是对外部ResultMa ...

  4. Mybatis使用时 resultMap与resultType、parameterMap与 parameterType的区别

    Map:映射:Type:Java类型  resultMap 与 resultType.parameterMap 与  parameterType的区别在面试的时候被问到的几率非常高,出现的次数到了令人 ...

  5. 深入浅出Mybatis系列(八)---mapper映射文件配置之select、resultMap

    上篇<深入浅出Mybatis系列(七)---mapper映射文件配置之insert.update.delete>介绍了insert.update.delete的用法,本篇将介绍select ...

  6. 深入浅出Mybatis系列(八)---mapper映射文件配置之select、resultMap good

    上篇<深入浅出Mybatis系列(七)---mapper映射文件配置之insert.update.delete>介绍了insert.update.delete的用法,本篇将介绍select ...

  7. Mybatis-利用resultMap 输出复杂pojo

    个:复杂的sql语句查询的数据集的字段和 pojo的字段不相同,需要用到resultMap做一个对应. ---------------- mybatis中使用resultMap完成高级输出结果映射. ...

  8. Mybatis 系列8-结合源码解析select、resultMap的用法

    [Mybatis 系列10-结合源码解析mybatis 执行流程] [Mybatis 系列9-强大的动态sql 语句] [Mybatis 系列8-结合源码解析select.resultMap的用法] ...

  9. Mybatis中parameterType、resultMap、statementType等等配置详解(标签中基本配置详解)

    一.(转自:https://blog.csdn.net/majinggogogo/article/details/72123185) 映射文件是以<mapper>作为根节点,在根节点中支持 ...

随机推荐

  1. [3D]绘制XYZ小坐标轴

    源码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Slim ...

  2. Perl Print Win32 Console Windows 控制台 print Unicode 问题

    参考资料: https://stackoverflow.com/questions/15224400/perl-on-windows-problems-with-encoding https://te ...

  3. iOS 图片循环滚动(切片效果)

                             #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIAp ...

  4. 虚拟化技术比较 PV HVM

    很多人看到同样配置的VPS价格相差很大,甚是不理解,其实VPS使用的虚拟技术种类有很多,如OpenVZ.Xen.KVM.Xen和HVM与PV.在XEN中pv是半虚拟化,hvm是全虚拟化,pv只能用于L ...

  5. defer 要放在return之前

    虽然defer可以在函数退出的时候执行,但是也要把它放在return之前,否则不会调用到. 错误的示范: res, err := Resource.open() if err != nil { ret ...

  6. arping 通知网关刷新IP

     arping -c 2 -I em1 -s 192.168.110.12  192.168.110.1  

  7. NLS_LANG参数说明

    NLS_LANG参数说明 格式:  NLS_LANG = language_territory.charset 它有三个组成部分(语言.地域和字符集),每个成分控制了NLS子集的特性.其中: Lang ...

  8. Volocity循环高级用法

    #foreach($announcementDo in $announcementList) #set($listSize=$!announcementList.size() - 1) #if(($v ...

  9. 《30天自制操作系统》06_day_学习笔记

    harib03a: 内容没有变化 :P109 从这里开始,代码开始工程化了. 将原本300多行的bootpack.c分割成了三部分: graphic.c      : 用来处理界面图像 dsctbl. ...

  10. Swift游戏实战-跑酷熊猫 03 熊猫跑动动画

    这节内容,我们一起来利用SKAction的来为熊猫创建动画,我们将学会通过纹理组产生动画,使用永远循环的SKAction让熊猫不停的跑动. 要点: 枚举的使用:用来记录熊猫的动作状态 enum Sta ...