zoukankan      html  css  js  c++  java
  • mybatis 多参数处理

    接口交互比较多, 所以 入参比较多,  有五个参数,是排序 参数, 跟这个五个参数排序,本来想写个对象的, 怕麻烦, 就把 五个参数 变成一个参数, 升序 1 ,降序2 ,比如  11221 ,第三第四个降序。

     mybatis 处理麻烦, 本来是想用charAt 的;

      mybatis sql:

      <if test=" order.chartAt[0]=='1' "> 结果总是报错, 用了 数字取余 完成了。

        select  b.* from(
            SELECT
                a.parent_category_name as first,
                a.category_name as second,
              a.fds as time,
                sum(a.bid_rtnum) AS flow,
                sum(a.pv) AS pv,
                sum(a.click) / sum(a.pv) AS ctr,
                sum(a.cost) / 100 / sum(a.pv) AS cpm,
                sum(a.cost) / 100 / 1000 / sum(a.click) AS cpc
            FROM
                rpt_app_category   a
            where 1=1
             and   (a.parent_category_name like CONCAT('%','${search}','%' )  or a.category_name like CONCAT('%','${search}','%' ))
              and a.fds &gt;=#{beginDate}
             and a.fds &lt;=#{endDate}
            GROUP BY
            <if test="flag==1">
                a.parent_category_id
            </if>
            <if test="flag==2">
               a.category_id
            </if>
            ) b
            ORDER BY
                b.time DESC
                <choose>
                <when test="order/10000%1000%100%10==1">
                , b.flow DESC
                </when>
                <otherwise>
                , b.flow ASC
                </otherwise>
                </choose>
                <choose>
                <when test="order/1000%100%10==1">
                , b.pv DESC
                </when>
                <otherwise>
                , b.pv ASC
                </otherwise>
                </choose>
                <choose>
                <when test="order/100%10==1">
                , b.ctr DESC
                </when>
                <otherwise>
                , b.ctr ASC
                </otherwise>
                </choose>
                <choose>
                <when test="order%100/10==1">
                , b.cpm DESC
                </when>
                <otherwise>
                ,b.cpm ASC
                </otherwise>
                </choose>
                <choose>
                <when test="order%100%10==1">
                , b.cpc DESC
                </when>
                <otherwise>
                ,b.cpc ASC
                </otherwise>
                </choose>
            LIMIT #{page},10

    这样就OK了,  随笔记下 ,下次 参考。

  • 相关阅读:
    内存
    TCP/IP
    安装
    linux常用命令
    linux文本处理三剑客之 grep
    tail命令:显示文件结尾的内容
    less命令:查看文件内容
    head命令:显示文件开头内容
    改进Zhang Suen细化算法的C#实现
    【转】在VS2010上使用C#调用非托管C++生成的DLL文件(图文讲解)
  • 原文地址:https://www.cnblogs.com/zgghb/p/5567018.html
Copyright © 2011-2022 走看看