• 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>
  • 相关阅读:
    CentOS7安装redis
    apache修改最大连接数报错
    阿里云服务器安全组设置
    CentOS7为firewalld添加开放端口
    php程序报错:PHP Core Warning/cannot open shared object file: No such file or directory
    centos7配置Apache支持HTTPS
    linux系统下Apache日志分割(按天生成文件)
    springboot 项目依赖 es包版本异常
    jboss Marshalling, 服务端收不到消息
    gateway 整合 websocket demo
  • 原文地址:https://www.cnblogs.com/LcxSummer/p/15034842.html
Copyright © 2020-2023  润新知