zoukankan      html  css  js  c++  java
  • Mybatis一对多的写法

    实体类

    
    public class AntennaSystem implements Serializable {
    	private static final long serialVersionUID = 1L;
    	
    	/**
    	* 系统id
    	*/
        private String systemId;
    	
    	/**
    	* 系统名称
    	*/
        private String systemName;
    	
    	/**
    	* 部门id
    	*/
    	private String departId;
    
    	/**
    	 * 部门
    	 */
        private Department department;
    	
    	/**
    	* 站主键id
    	*/
    	private String stationId;
    
    	/**
    	 * 站
    	 */
        private Station station;
    	/**
    	 * 扩展属性
    	 */
    	private List<ExtendedAttr> extendedAttrs;
    
    	/**
    	 * 分系统
    	 */
    	private List<Subsystem> subsystems;
    }
    

    Mapper.xml

    
        <!-- 可根据自己的需求,是否要使用 -->
        <resultMap type="com.industry.txsp.entity.AntennaSystem" id="baseAntennaSystemMap">
            <result property="systemId" column="system_id"/>
            <result property="systemName" column="system_name"/>
            <result property="departId" column="depart_id"/>
            <result property="stationId" column="station_id"/>
            <result property="completeDate" column="complete_date"/>
            <result property="deliveryDate" column="delivery_date"/>
            <result property="qaDeadline" column="qa_deadline"/>
            <result property="systemNumber" column="system_number"/>
            <result property="remark" column="remark"/>
            <result property="createId" column="create_id"/>
            <result property="creator" column="creator"/>
            <result property="createTime" column="create_time"/>
            <result property="updateTime" column="update_time"/>
            <result property="isDeleted" column="is_deleted"/>
        </resultMap>
        
        <!--分开来写有利于解耦,更灵活-->
        <!--extends:可以继承一个已有的resultMap,指定resultMap的唯一标识(id)即可,但是在继承时,只能继承type类型一样的resultMap-->
        <resultMap extends="baseAntennaSystemMap" type="com.industry.txsp.entity.AntennaSystem" id="antennaSystemMap">
            <association property="department" resultMap="com.industry.txsp.mapper.DepartmentMapper.departmentMap"/>
            <association property="station" resultMap="com.industry.txsp.mapper.StationMapper.stationMap"/>
        </resultMap>
    
         
        <resultMap extends="antennaSystemMap" type="com.industry.txsp.entity.AntennaSystem" id="allAntennaSystemMap">
            <collection property="subsystems" resultMap="com.industry.txsp.mapper.SubsystemMapper.subsystemMap"/>
            <collection property="extendedAttrs" resultMap="com.industry.txsp.mapper.ExtendedAttrMapper.extendedAttrMap"/>
        </resultMap>
    
  • 相关阅读:
    第三章第四章总结
    java学习2打架代码编写
    windows server 2008 远程桌面(授权、普通用户登录)
    Windows组建网络服务 ——WEB服务器的组建与架构
    windows server 2008 站点系列
    将 Ubuntu 加入到 Windows 2003 AD域
    Windows Server 2008组策略管理与配置
    AD用户设置系列
    利用windows 2003实现服务器群集的搭建与架设
    server2008 跨进新的平台(三)高端的备份还原工具
  • 原文地址:https://www.cnblogs.com/junzifeng/p/12736313.html
Copyright © 2011-2022 走看看