• 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>
  • 相关阅读:
    CentOS 编译安装 MySQL5.7
    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了
    Linux里如何查找文件内容
    linux怎么模糊查找一个文件
    centos7下使用yum安装mysql
    centos下完全卸载mysql
    Linux下安装配置Nexus
    Linux下建立Nexus私服
    阿里云主机上安装jdk
    java war run
  • 原文地址:https://www.cnblogs.com/LcxSummer/p/15034842.html
Copyright © 2020-2023  润新知