• mybatis 一对多和一对一写法注意事项


      <resultMap id="ChartResultMap" type="com.qif.dsa.ucenter.planinfo.entity.ChartDate">
            <id column="time" jdbcType="VARCHAR" property="time"/>
            <collection property="planChartList"   javaType="java.util.List"
                        column="time" ofType="com.qif.dsa.ucenter.planinfo.entity.PlanChart" >
                <id column="time" jdbcType="VARCHAR" property="time" />

    下面的i-State 是数据库里的字段, iState 则是展示到页面的字段
    <result column="i_State" jdbcType="VARCHAR" property="iState" /> <result column="stateCount" jdbcType="INTEGER" property="stateCount" /> </collection> </resultMap>


    以上写法用于一对多select..... leftjoin .....
      <resultMap id="BigTypeResultMap" type="com.qif.dsa.ucenter.bigtype.entity.BigType">
            <id column="BigTypeId" jdbcType="INTEGER" property="bigTypeId" />
            <result column="vc_Name" jdbcType="VARCHAR" property="vcName" />
    
          这里的BigTypeId 作为外键 
        querySmallTypeByBigId方法是另外一个dao层里面通过外键查到的数据 一次返回
    <collection property="smallTypeList" column="BigTypeId" select="com.qif.dsa.ucenter.smallType.dao.SmallTypeDao.querySmallTypeByBigId"/> </resultMap>
    
    
    
    
    以上写法用于一对多 select.....(包含外键)
    原理:    一条不关联的sql 里面包含外键 
             当返回值为带有 select  的collection时,自动从别的表调用查询语句 返回整体结果                   
    <resultMap id="HazardResultMap" type="com.qif.dsa.ucenter.hazardinfo.entity.HazardInfo">
            <id column="HazardID" jdbcType="INTEGER" property="hazardId" />
            <result column="RcuID" jdbcType="INTEGER" property="rcuId" />
            <result column="vc_HazardContent" jdbcType="VARCHAR" property="vcHazardContent" />
            <result column="vc_FillPeople" jdbcType="VARCHAR" property="vcFillPeople" />
            <association property="rcuInfo" javaType="com.qif.dsa.ucenter.rcuinfo.entity.RcuInfo" columnPrefix="rcu_">
                <id property="rcuId" jdbcType="INTEGER" column="RcuID"/>
                <result property="orgId" jdbcType="INTEGER" column="OrgID"/>
                <result property="vcName" jdbcType="VARCHAR"  column="vcName"/>
            </association>
        </resultMap>


    以上写法用于一对一  select..... innerjoin   .....  
     
  • 相关阅读:
    hadoop的权限控制
    linux ssh连接超时断连设置
    PuTTY + Xming 远程使用 Linux GUI
    linux系统用户下的crontab任务不执行问题处理
    shell编程注意点
    启动VMware出现报错:The VMware Authorization Service is not running
    mul8_unsigned multipliter
    mul16
    C#基础精华06(Linq To XML,读取xml文件,写入xml)
    C#基础精华05(正则表达式,)
  • 原文地址:https://www.cnblogs.com/MagicAsa/p/11171028.html
Copyright © 2020-2023  润新知