zoukankan      html  css  js  c++  java
  • MyBatis查询汇总

    <select id :和dao层方法名相同

    resultType / resultMap:二选一

    resultType的值是一个类或者int ,比如com.business.entity.RepayChannel

    resultMap是在本xml下定义的一个字段集合,比如Integer

    现在有储蓄卡表deposit(id,card_no)、还款渠道表channel(id,name)、中间表deposit_channel(id,deposit_id,channel_id)

    deposit和channel的关系是一对多,关系记录在中间表deposit_channel

    现在希望实现一个接口selectDeposit:查询出多条储蓄卡,且每条都包含它所属的所有渠道。

    1、修改deposit的entity,加入属性(不会影响其他查询deposit记录但不需要渠道记录的接口)

    private List<Channel> channels

    2、mapper.xml

    <sql id="Base_Column_List">
    id,card_no
    </sql>
    <resultMap id="DepositChannelResult" type="com.cardniu.ccrepayment.business.entity.Deposit">
    <id column="id" property="id" jdbcType="BIGINT"/>
    <result column="card_no" property="cardNo" jdbcType="VARCHAR"/>
    <!--collection的column表示关联性,此处相当于deposit.id=channel.id-->
    <collection property="channels" javaType="ArrayList" column="id" ofType="com.business.entity.Channel" select="selectChannelForDeposit"/>
    </resultMap>
    <!--此处parameterType和DepositChannelResult中collection的column的类型一致-->
    <!--此关联查询如果传参有多个,parameterType要改为map,这里只有id,所以不改-->
    <select id="selectChannelForDeposit" resultType="com.business.entity.Channel" parameterType="int">
    select 
    R.name
    from deposity_channel D, channel R 
    where D.deposit_id=#{deposit_id} and D.channel_id=R.id
    </select>
    <select id="selectDeposit" resultMap="DepositChannelResult" parameterType="map">
    select 
    <include refid="Base_Column_List" /> 
    from deposit
    </select>

    Done!

  • 相关阅读:
    MYSQL新特性secure_file_priv对读写文件的影响
    weblogic反序列化漏洞CVE-2018-2628-批量检测脚本
    WebLogic WLS-WebServices组件反序列化漏洞—Linux可执行反弹一句话版本
    攻击溯源_一次断网事件的分析
    建立加密socks5转发的两种方法
    【原创】Flash XSS 挖掘
    【转载】SQL的注入类型
    【原创】批处理文本
    【转载】nmap 官方指南
    【转载】对抗 DDoS 攻击的 15 个方法
  • 原文地址:https://www.cnblogs.com/xingyyy/p/7213837.html
Copyright © 2011-2022 走看看