iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >mybatis中的if test判断入参的值问题
  • 848
分享到

mybatis中的if test判断入参的值问题

2024-04-02 19:04:59 848人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

目录mybatis if test判断入参的值1.第一种判断方式2.第二种判断方式if test动态判断数字时出现的错误mybatis中if test判断数字mybatis if t

mybatis if test判断入参的值

1.第一种判断方式

<if test=' requisition != null and requisition == "Y" '>
   AND 表字段 = #{requisition}
</if>

2.第二种判断方式

<if test=" requisition != null and requisition == 'Y'.toString() ">
  AND 表字段 = #{requisition}
</if>

if test动态判断数字时出现的错误

mybatis中if test判断数字

在实现搜索功能时碰到的错误,很多时候我们会在数据库中使用一个字段来作为状态保存,如:0=男,1=女;0=禁止,1=启用等。

无论我选择停用、还是启用,都将整个表格的数据显示出来,没有起到筛选的作用。

通过排除,找到了导致问题的代码:

    <select id="queryAllByLimit" resultMap="SystemMenuMap">
        select
          id, pid, title, icon, href, sort, status
        from system_menu
        <where>
            <if test="systemMenu.status != null and systemMenu.status != '' ">
                and status = #{systemMenu.status}
            </if>
        </where>
    </select>

改为:

    <select id="queryAllByLimit" resultMap="SystemMenuMap">
        select
          id, pid, title, icon, href, sort, status
        from system_menu
        <where>
            <if test="systemMenu.status != null">
                and status = #{systemMenu.status}
            </if>
        </where>
    </select>

原因:

<if test="systemMenu.status != null and systemMenu.status != '' ">

只对判断String类型的字符串时起作用,由于status是Integer类型,判断条件不成立,没起到作用。如:当传入的值是1时,’1’会被解析成字符。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: mybatis中的if test判断入参的值问题

本文链接: https://www.lsjlt.com/news/150624.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作