===================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. I.MX6 WIFI wireless_tools 移植

    /******************************************************************************** * I.MX6 WIFI wirel ...

  2. css中的zoom的使用

    css中的zoom的使用  zoom : normal | number  normal : 默认值.使用对象的实际尺寸  number : 百分数 | 无符号浮点实数.浮点实数值为1.0或百分数为1 ...

  3. mvc理念和thinkphp的语法特征 thinkphp引入模板

    mvc即模型(model)-视图(view)-控制器(controller)的缩写 控制器很重要,功能性的东西要靠它实现,模型我还没接触到,只知道它对数据库负责,类似一个大控件吧... 速度... 一 ...

  4. popen&pclose管道方式操作shell命令

    popen, pclose - pipe stream to or from a process FILE *popen( const char *command, const char *type) ...

  5. 三层交换机+二层交换机配置VLAN相互访问

    使用思科模拟软件Cisco Packet Tracer Student,软件功能有限,只能架设简单的网络架构,适合初学者使用.

  6. windows 64位 dll文件 位置及python包rtree shapely安装

    位置 \Windows\System32 python包依赖包安装 rtree 依赖 spatialindex(spatialindex.dll   spatialindex_c.dll) shape ...

  7. less 初试

    第一次接触less,做些记录. 官网     民间中文文档      less notepad++插件 1. 支持变量声明 支持颜色.大小等相加 @nice-blue: #5B83AD; @light ...

  8. Emacs 列编辑

    copy from http://chandlewei.blogbus.com/logs/15583440.html 不敢独享,与大家分享.也可以在Emacs中用C-x C-h列出全部命令,查找C-x ...

  9. PostgreSQL中美元符号引用的字符串常量

    虽然用于指定字符串常量的标准语法通常都很方便,但是当字符串中包含了很多单引号或反斜线时很难理解它,因为每一个都需要被双写.要在这种情形下允许可读性更好的查询,PostgreSQL提供了另一种被称为“美 ...

  10. G面经prepare: Maximum Subsequence in Another String's Order

    求string str1中含有string str2 order的 subsequence 的最小长度 DP做法:dp[i][j]定义为pattern对应到i位置,string对应到j位置时,shor ...