Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<if test="">位运算体验问题 #983

Open
hanyu658 opened this issue Apr 9, 2024 · 8 comments
Open

<if test="">位运算体验问题 #983

hanyu658 opened this issue Apr 9, 2024 · 8 comments

Comments

@hanyu658
Copy link

hanyu658 commented Apr 9, 2024

场景如下 判断flagBit最后1,2,3位是否为1

<if test="(query.flagBit &amp; 1) != 0">
    UNION ALL
    sql...
</if>
<if test="(query.flagBit &amp; 2) != 0">
    UNION ALL
    sql...
</if>
<if test="(query.flagBit &amp; 4) != 0">
    UNION ALL
    sql...
</if>
image

此时需要自己勾选true 而不是填写flagBit值 自动运算

希望未来版本可以优化这个场景

@gejun123456
Copy link
Owner

好建议 根据参数自动计算if test的值

@gejun123456
Copy link
Owner

image
可以先使用插件生成testcase那个功能 快速测试xml的sql
https://brucege.com/doc/#/quicktestsql

@hanyu658
Copy link
Author

image 可以先使用插件生成testcase那个功能 快速测试xml的sql https://brucege.com/doc/#/quicktestsql

学到了新姿势。
不过最初期望是:利用插件预览组装的sql是否符合预期(因为我的场景比较特殊),而不是校验执行结果。

感谢回复!

@gejun123456
Copy link
Owner

通过参数值来给ifTest赋值

实现了一个简单的解析,3.3.2发布哈,明天打个包

@hanyu658
Copy link
Author

遇到两个小问题
veersion 3.3.2+2322

  1. 如果SQL中没有用到参数, 比如condition1仅在标签test中使用变量, 预览SQL时type参数好像不支持输入文本框?
  2. 我试了下type赋值1 , [√] type==2 也是被选中的 ☹️
<select id="sqlTest" resultType="java.lang.Integer">
    select 1 from table
    <where>
        <if test="query.type == 1">
            AND condition1 = 1
        </if>
        <if test="query.type == 2">
            AND condition2 = #{query.type}
        </if>
    </where>

    <if test="query.sort != null">
        ORDER BY
        <choose>
            <when test="query.sort == 1">
                create_time desc
            </when>
            <when test="query.sort == 2">
                update_time desc
            </when>
            <otherwise>
            
            </otherwise>
        </choose>
    </if>
</select>

@hanyu658
Copy link
Author

2024-05-16.18.55.05.mov

录了个使用流程,是姿势不对吗 (转.gif发现文件更大了… 直接上传附件了)

@gejun123456
Copy link
Owner

谢谢反馈 这种使用 . 号的支持还没弄,我优化一下

@gejun123456
Copy link
Owner

插件可以加个 去识别 if test 里面有哪些参数 然后通过值来控制

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants