zoukankan      html  css  js  c++  java
  • 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   .....  
     
  • 相关阅读:
    electron 显示对话框 showMessageBoxSync showMessageBox
    c++ 随机数 取值范围 多线程
    c++ 字符串转换为数字
    VS2019 C++动态链接库的创建使用(1)
    js mutationobserver property vs attribute
    Chromium base 基础库概览
    Git:合并分支----git merge命令应用的三种情景
    chromium 处理 addEventListener 事件
    JavaScript监听属性改变
    chrome 启动开关参数
  • 原文地址:https://www.cnblogs.com/MagicAsa/p/11171028.html
Copyright © 2011-2022 走看看