欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mybatis的管理映射

程序员文章站 2022-07-13 16:06:22
...

mybatis的管理映射:

主查询有结果才会促发子查询

 

比如同时有A.java和B.java两个类,A.java如下:

public class A{

    private B b1;

    private List<B> b2;

}

在映射b1属性时用association标签, 映射b2时用collection标签,分别是一对一,一对多的关系

 

 

 <resultMap id="BaseResultMapVo" type="com.esteel.system.beanVo.OpmUserVo" >

    <id column="ID" property="id" jdbcType="VARCHAR" />

    <result column="CODE" property="code" jdbcType="VARCHAR" />

    <result column="PASSWORD" property="password" jdbcType="VARCHAR" />

    <result column="NAME" property="name" jdbcType="VARCHAR" />

    <result column="TELEPHONE" property="telephone" jdbcType="VARCHAR" />

    <result column="EMAIL" property="email" jdbcType="VARCHAR" />

    <result column="ORGANID" property="organid" jdbcType="VARCHAR" />

    <result column="VALID" property="valid" jdbcType="VARCHAR" />

    <result column="MEMO" property="memo" jdbcType="VARCHAR" />

    <result column="LEVEL1" property="level1" jdbcType="DECIMAL" />

    <result column="LAST_LOGIN_DATE" property="lastLoginDate" jdbcType="VARCHAR" />

    <result column="LAST_LOGIN_TIME" property="lastLoginTime" jdbcType="TIMESTAMP" />

    <result column="ONLINE_MARK" property="onlineMark" jdbcType="VARCHAR" />

    <result column="ONLINE_IP" property="onlineIp" jdbcType="VARCHAR" />

    <result column="SESSIONID" property="sessionid" jdbcType="VARCHAR" />

    <collection property="opmRole" ofType="com.esteel.system.bean.OpmRole" select="getr" column="{uId=ID}">

    </collection>

  </resultMap>

 

<select id="getUserByMarkId" parameterType="map" resultMap="BaseResultMapVo">

 select o.*

       from opm_User o 

      where 1 = 1

 <if test="organid!=null and organid!=''"> 

      and o.organId=#{organid} 

 </if>

 <if test="valid!=null and valid!=''"> 

       and o.valid=#{valid} 

 </if>

 <if test="level1!=null and level1!=''"> 

      and o.LEVEL1=#{level1}

 </if>

  order by o.code

  </select>

  <select id="getr" resultMap="BaseResultMapr">

  select r.* from opm_role r join opm_user_role ur on ur.roleid = r.id  join opm_User o on o.id = ur.userid  

  and o.id=#{uId}

  </select>

 

 

=====================================================

 

 

 

 <resultMap id="BaseResultMapVo" type="com.esteel.bank.beanVo.TbFndMktIaoVo" >

    <!--

      WARNING - @mbggenerated

    -->

    <id column="MKT_IAO_KEY" property="mktIaoKey" jdbcType="DECIMAL" />

    <result column="MKT_IAO_ID" property="mktIaoId" jdbcType="VARCHAR" />

    <result column="BILL_ID" property="billId" jdbcType="VARCHAR" />

    <result column="SIGN_ACCOUNT_BANK" property="signAccountBank" jdbcType="VARCHAR" />

    <result column="BANK_ID" property="bankId" jdbcType="VARCHAR" />

    <result column="BANK_NO" property="bankNo" jdbcType="VARCHAR" />

    <result column="MARKET_KEY" property="marketKey" jdbcType="DECIMAL" />

    <result column="CUSTOMER_KEY" property="customerKey" jdbcType="DECIMAL" />

    <result column="CUSTOMER_SON_KEY" property="customerSonKey" jdbcType="DECIMAL" />

    <result column="SUBJECT_ID" property="subjectId" jdbcType="VARCHAR" />

    <result column="OCR_MONEY" property="ocrMoney" jdbcType="DECIMAL" />

    <result column="ACCOUNT_TYPE" property="accountType" jdbcType="CHAR" />

    <result column="UNDO_TYPE" property="undoType" jdbcType="CHAR" />

    <result column="REFRESH_TYPE" property="refreshType" jdbcType="CHAR" />

    <result column="MONEY_USE" property="moneyUse" jdbcType="VARCHAR" />

    <result column="ADD_USER" property="addUser" jdbcType="VARCHAR" />

    <result column="ADD_DATE" property="addDate" jdbcType="VARCHAR" />

    <result column="ADD_TIME" property="addTime" jdbcType="TIMESTAMP" />

    <result column="ADD_IP" property="addIp" jdbcType="VARCHAR" />

    <result column="LAB_USER" property="labUser" jdbcType="VARCHAR" />

    <result column="LAB_DATE" property="labDate" jdbcType="VARCHAR" />

    <result column="LAB_TIME" property="labTime" jdbcType="TIMESTAMP" />

    <result column="LAB_MSG" property="labMsg" jdbcType="VARCHAR" />

    <result column="CHK_USER" property="chkUser" jdbcType="VARCHAR" />

    <result column="CHK_DATE" property="chkDate" jdbcType="VARCHAR" />

    <result column="CHK_TIME" property="chkTime" jdbcType="TIMESTAMP" />

    <result column="CHK_IP" property="chkIp" jdbcType="VARCHAR" />

    <result column="CUR_STA" property="curSta" jdbcType="CHAR" />

    <result column="NOTE" property="note" jdbcType="VARCHAR" />

    <result column="CONT_DATE" property="contDate" jdbcType="VARCHAR" />

    <result column="OPEN_ACCUSER_NAME" property="openAccuserName" jdbcType="VARCHAR" />

    <result column="OPEN_BANK_NAME" property="openBankName" jdbcType="VARCHAR" />

    <result column="ACCOUNT_ID" property="accountId" jdbcType="VARCHAR" />

    <result column="PAY_BANK" property="payBank" jdbcType="VARCHAR" />

    <result column="PAY_BANK_NO" property="payBankNo" jdbcType="VARCHAR" />

    <result column="PAY_NO" property="payNo" jdbcType="VARCHAR" />

    <association property="tbCusFirm" select="getCus" column="{cuslumn=CUSTOMER_KEY}" javaType="com.esteel.system.bean.TbCusFirm"></association>

  </resultMap>

  <select id="getCus" resultType="com.esteel.system.bean.TbCusFirm">

    select * from TB_CUS_FIRM kt where kt.CUSTOMER_KEY=#{cuslumn}

  </select>

  

  <select id="getFndMktIaoList" resultMap="BaseResultMapVo" parameterType="map">

  

     select * from TB_FND_MKT_IAO t where 1=1 

      AND t.SUBJECT_ID not in ('A003','A004')

    <if test="MKT_IAO_ID!=null and MKT_IAO_ID!=''">

      AND t.MKT_IAO_ID like '%'|| lower(trim(#{MKT_IAO_ID})) ||'%'

    </if>

    <if test="CUR_STA!=null and CUR_STA!=''">

      AND t.CUR_STA = #{CUR_STA}

    </if>

    <if test="MKT_IAO_KEY!=null and MKT_IAO_KEY!=''">

      AND t.MKT_IAO_KEY = #{MKT_IAO_KEY}

    </if>

    <if test="SUBJECT_ID!=null and SUBJECT_ID!=''">

      AND t.SUBJECT_ID = #{SUBJECT_ID}

    </if>

    <if test="CUSTOMER_KEY!=null and CUSTOMER_KEY!=''">

      AND t.CUSTOMER_KEY <![CDATA[<>]]> #{CUSTOMER_KEY}

    </if>

    <if test="ADD_USER!=null and ADD_USER!=''">

      AND t.ADD_USER <![CDATA[<>]]> #{ADD_USER}

    </if>

    <if test="CUSTOMER_ID!=null and CUSTOMER_ID!=''">

      AND t.CUSTOMER_ID like '%'|| lower(trim(#{CUSTOMER_ID})) ||'%'

    </if>

    <if test="CUSTOMER_NAME!=null and CUSTOMER_NAME!=''">

      AND t.CUSTOMER_NAME like '%'|| lower(trim(#{CUSTOMER_NAME})) ||'%'

    </if>

    <if test="START_ADD_TIME!=null and START_ADD_TIME!=''">

      AND to_char(t.ADD_TIME,'yyyy-mm-dd') <![CDATA[>=]]> #{START_ADD_TIME}

    </if>

    <if test="END_ADD_TIME!=null and END_ADD_TIME!=''">

       AND to_char(t.ADD_TIME,'yyyy-mm-dd') <![CDATA[<=]]> #{END_ADD_TIME}

    </if>

    order by t.CUR_STA,t.MKT_IAO_ID asc

  </select>

 

相关标签: mybatis