zoukankan      html  css  js  c++  java
  • mybatis resultMap 复用

     使用同一个命名空间里的resultMap,这里的 BaseResultMap 在另一个xml文件中,但是两个文件的命名空间是一样的

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.cetcht.dao.device.AllInfoMapper">
      
      <resultMap id="TypeListMap" type="com.cetcht.vo.scene.AllInfoTypeVo">
          <result column="class_name_cn" jdbcType="VARCHAR" property="classNameCn" />
        <collection property="infoList" ofType="com.cetcht.entity.device.AllInfo" resultMap="BaseResultMap">
        </collection>
      </resultMap>
      
      <select id="selectTypeList" parameterType="java.lang.String" resultMap="TypeListMap">
        SELECT * from s_all_info WHERE orgz_code LIKE #{orgzCode}
      </select>
      
    </mapper>

    使用不同命名空间里的resultMap,这里的 com.cetcht.dao.device.AllInfoMapper.BaseResultMap 是引用的另一个命名空间里的 BaseResultMap, 这里的 extends="BaseResultMap" 是同一个命名空间里定义的 BaseResultMap

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.cetcht.dao.scene.SceneBeanMapper">
      
      <resultMap id="BeanAllInfoMap" type="com.cetcht.entity.scene.SceneBean" extends="BaseResultMap">
        <association property="infoDetail" resultMap="com.cetcht.dao.device.AllInfoMapper.BaseResultMap" >
            <result column="entity_id" jdbcType="BIGINT" property="id" />
           </association>
      </resultMap>
      
      <select id="selectSceneBeanList" parameterType="java.lang.Long" resultMap="BeanAllInfoMap">
        SELECT * from b_scene_bean bean_ 
        RIGHT JOIN s_all_info info_ ON bean_.entity_id = info_.id AND bean_.entity_table_name = info_.class_name
        WHERE bean_.scene_id = #{sceneId}
      </select>
      
    </mapper>
  • 相关阅读:
    POJ3662 Telephone Lines (dijkstra+二分)
    Codeforces Round #618 (Div. 2)A. Non-zero
    Codeforces Round #618 (Div. 2)C. Anu Has a Function
    洛谷P1060开心的金明(滚动数组优化)
    洛谷P1006传纸条
    Spring Boot中以代码方式配置Tomcat
    js常用方法总结(以后遇到再进一步总结)
    localStorage的使用
    巧用Ajax的beforeSend 提高用户体验
    四种会话跟踪技术
  • 原文地址:https://www.cnblogs.com/LcxSummer/p/15034842.html
Copyright © 2011-2022 走看看