mybatis查询参数中既有 实体类参数又有基本类型参数 解决方案

这个方法真实有效,直接上代码
DAO中的查询方法

public LogisticNodes findFirstNode(
@Param("ln")LogisticNodes ln,@Param("stringId")String stringId);

第一个参数为实体类,需要加上@param()注解
xml中的写法

        SELECT
            <include refid="logisticNodesColumns"/>
        FROM
            order_logistic_nodes a
        <where>                     
                <if test="ln.id != null and ln.id !=''">
                     AND a.id = #{ln.id,jdbcType=VARCHAR}
                </if>
                <if test="ln.nodeName != null and ln.nodeName !=''">
                     AND a.node_name = #{ln.nodeName,jdbcType=VARCHAR}
                </if>
               <if test="ln.nodeSort != null">
                     AND a.node_sort = #{ln.nodeSort,jdbcType=DECIMAL}
               </if>
        </where>
        and
            a.logistic_type IN (
                SELECT
                    s.logistic_type
                FROM
                    order_logistic_nodes s
            <where>                     
                <if test="stringId != null and stringId !=''">
                      s.id = #{stringId,jdbcType=VARCHAR}
                </if>
           </where>
        )
        order by a.node_sort
        limit 1

xml中,取实体类的属性前面要加上类的引用

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值