元气满满旁白菌 2023-05-10 01:35 采纳率: 100%
浏览 28
已结题

关于MySql中choose when的用法


    select id, shop_id, order_id, user_id, detail, shop_score, quality_score, packaging_score, rider_score,
    del_flag, create_time, update_time,evaluate_img from evaluate_info
    <where>
        <if test="vo.score!=null and vo.score !=''">
            <if test="vo.score == 2">
                and 1=1
            </if>
            and shop_score=#{vo.score}
        </if>
        <if test="vo.reply!=null and vo.reply != '' ">
            <choose>
                <when test="vo.reply = '1' ">
                    and apply = '1'
                </when>
                <when test="vo.reply = '2' ">
                    and apply = '0'
                </when>
            </choose>
        </if>
        <if test="vo.content != null and vo.content != '' ">
            <choose>
                <when test="vo.content = '1' ">
                    and evaluate_img is not null
                </when>
                <when test="vo.content = '2' ">
                    and evaluate_img is null
                </when>
            </choose>
        </if>
        <if test="vo.month!=null and vo.month !=''">
            and date_format (create_time,'%Y-%m-%d') between date_format (#{vo.firstDay},'%Y-%m-%d') and
            date_format (#{vo.lastDay},'%Y-%m-%d')
        </if>
    </where>
</select>

在查询时,当我reply或content传值为1时,sql正常运行,当传值为2时,拼接出来的sql出现问题,仍然是传值为1时的sql

  • 写回答

1条回答 默认 最新

  • 创意程序员 2023-05-10 06:50
    关注

    test里面的表达式要用==,你只用了一个=

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 5月18日
  • 已采纳回答 5月10日
  • 创建了问题 5月10日

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号