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   .....  
     
  • 相关阅读:
    c# Invalidate() Update() Refresh()的区别
    Winform重画ComboBox背景色
    窗口过程 Wndproc
    设置DatagridView的列头样式
    SQL2005 全文检索超时的解决方案
    winform 获取当前程序运行根目录
    Web API-如何将Controller的返回值转换成HTTP response消息
    ASP.NET Web API 如何通过程序控制返回xml还是json
    C# web api返回类型设置为json的两种方法
    多组 RadioButtonList 获取值
  • 原文地址:https://www.cnblogs.com/MagicAsa/p/11171028.html
Copyright © 2011-2022 走看看