mybatis报错:
?
1
|
错误代码:
?
1
2
3
4
5
6
7
8
9
10
11
12
|
<select id= "selectaccountlist" resultmap= "baseresultmap" >
select ct.customer_name customername,sam.city_code,sam.user_name,sam.account_name
from sys_account_manager sam left join sys_customer ct on ct.id = sam.customer_id
where sam.deleted = 0
< if test= "customername != null and customername != '' " >
and ct.customer_name like concat( '%' ,#{customername}, '%' )
</ if >
< if test= "citycode != null and citycode != '' " >
and locate(#{citycode},sam.city_code)
</ if >
order by status,account_validity_time desc
</select>
|
正确代码:
原因是:
?
1
2
3
4
5
6
7
8
9
10
11
12
|
<select id= "selectaccountlist" resultmap= "baseresultmap" >
select ct.customer_name customername,sam.city_code,sam.user_name,sam.account_name
from sys_account_manager sam left join sys_customer ct on ct.id = sam.customer_id
where sam.deleted = 0
< if test= "customername != null and customername != '' " >
and ct.customer_name like concat( '%' ,#{customername}, '%' )
</ if >
< if test= "citycode != null and citycode != '' " >
and locate(#{citycode},sam.city_code)
</ if >
order by status,account_validity_time desc
</select>
|
补充:mybatis中if判断遇到的坑
最近在项目开发的过程中,遇到了mybatis的一个坑(也许是mybatis有意这样设计的),对于integer或者long这种引用数据类型,在做if判断的时候,如果引用数据类型为0,则mybatis将会视为”“空字符串,所以走不进判断逻辑里。
以下余额字段为long类型,availableamount值为0时,将走不进判断方法内的示例截图:
解决方法:
在test判断条件中添加”or availableamount==0“即可,以下是示例截图:
或者在业务场景允许的情况下,只判断availableamount!=null
?
1
2
3
|
< if test= "availableamount!=null" >
...
</ if >
|
以上为个人经验,希望能给大家一个参考,也希望大家多多支持快网idc。如有错误或未考虑完全的地方,望不吝赐教。
原文链接:https://blog.csdn.net/weixin_39093006/article/details/91041819
相关文章
猜你喜欢
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
- ASP.NET自助建站系统中如何实现多语言支持? 2025-06-10
- 64M VPS建站:如何选择最适合的网站建设平台? 2025-06-10
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-29 104
-
2025-05-29 13
-
2025-06-04 70
-
BigCommerce vs Shopify:谁是最佳傻瓜式建站解决方案?
2025-06-05 35 -
2025-05-27 18
热门评论