mybatis if test判断入参的值
1.第一种判断方式
1
2
3
|
< if test = ' requisition != null and requisition == "Y" ' > AND 表字段 = #{requisition} </ if > |
2.第二种判断方式
1
2
3
|
< if test = " requisition != null and requisition == 'Y'.toString() " > AND 表字段 = #{requisition} </ if > |
if test动态判断数字时出现的错误
mybatis中if test判断数字
在实现搜索功能时碰到的错误,很多时候我们会在数据库中使用一个字段来作为状态保存,如:0=男,1=女;0=禁止,1=启用等。
无论我选择停用、还是启用,都将整个表格的数据显示出来,没有起到筛选的作用。
通过排除,找到了导致问题的代码:
1
2
3
4
5
6
7
8
9
10
|
< 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 > |
改为:
1
2
3
4
5
6
7
8
9
10
|
< 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 > |
原因:
1
|
< if test = "systemMenu.status != null and systemMenu.status != '' " > |
只对判断String类型的字符串时起作用,由于status是Integer类型,判断条件不成立,没起到作用。如:当传入的值是1时,’1’会被解析成字符。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://www.cnblogs.com/sikuaiwu/p/11387186.html