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>
    
  • 相关阅读:
    如何在ASP.NET 5和XUnit.NET中进行LocalDB集成测试
    如何在单元测试过程中模拟日期和时间
    Azure Blob Storage从入门到精通
    免费电子书:使用VS Online敏捷管理开源项目
    使用ASP.NET 5开发AngularJS应用
    Syncfusion的社区许可及免费电子书和白皮书
    理解ASP.NET 5的中间件
    惊鸿一瞥(Glimpse)——开发之时即可掌控ASP.NET应用的性能
    用于Simple.Data的ASP.NET Identity Provider
    大数据技术之_19_Spark学习_01_Spark 基础解析小结(无图片)
  • 原文地址:https://www.cnblogs.com/junzifeng/p/12736313.html
Copyright © 2011-2022 走看看