===================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. saltstack之(十)扩展组件salt-ssh

    场景:公司有50台服务器,需要安装salt-minion客户端,并完成与salt-master的认证,接受salt-master的管理.本片文章只用了2台服务器做演示,大家可以在roster文件中定义 ...

  2. CentOS6.5Minimal安装Gitlab7.5

    文章出处:http://www.restran.net/2015/04/09/gilab-centos-installation-note/ 在 CentOS 6.5 Minimal 系统环境下,用源 ...

  3. jquery.form插件

    提交表单的2种方式 // ajaxForm        $("#form1").ajaxForm(options);         // ajaxSubmit        $ ...

  4. javascript设计模式学习之二——this

    一.this指向问题 1)默认绑定,即作为独立的普通函数调用 此时this指向全局对象window,如果是严格模式下,则指向undefined; 2)隐式绑定,即具有调用上下文(一种场景就是作为对象的 ...

  5. Spring Security HTTP Basic for RESTFul and FormLogin (Cookies) for web - Annotations

    @Configuration @EnableWebMvcSecurity @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabl ...

  6. grunt搭建前端自动化实践

    grunt是什么? grunt是一个前端构建工具, 每种应用开发, 都有一套构建工具, 例如linux c程序开发, 构建工具是make, java程序的构建工具为maven,web前端经过十多年的发 ...

  7. ssh隧道技术

    大家都知道SSH是一种安全的传输协议,用在连接服务器上比较多.不过其实除了这个功能,它的隧道转发功能更是吸引人.下面是个人根据自己的需求以及在网上查找的资料配合自己的实际操作所得到的一些心得. SSH ...

  8. mysql explain 命令讲解

    explian命令可以显示select语句的执行计划 explain的结果中每行对应select语句中的一个表,输出结果中的顺序是按照语句处理表的顺序. mysql使用嵌套循环来处理所有的join连接 ...

  9. 线段树 Interval Tree

    一.线段树 线段树既是线段也是树,并且是一棵二叉树,每个结点是一条线段,每条线段的左右儿子线段分别是该线段的左半和右半区间,递归定义之后就是一棵线段树. 例题:给定N条线段,{[2, 5], [4, ...

  10. php-引号中出现$

    当双引号中包含变量时,变量对应的值会与双引号中的内容连接在一起: 当单引号中包含变量时,变量会被当做字符串输出. 慕课网,I love you!慕课网,$love