Mybatis中sql语句中的in查询,一定要判断null的情况
不严谨的写法,可能会报错:in (),这种情况不符合mysql的语法。select from loanwhere LOAN_ID in
#{item}
要么在Mybatis的sql文件中,要么在Java程序中。
sql中的写法:
select *
from p2p_loan_variation where 1= 1
and LOAN_ID in
#{item}
and 1=0
Java中的写法:
List list = null;
if(ListUtils.isNotEmpty(loadIds){
list =loanVariationDao.findByLoanIds(loanIds);
}
return list;
如果有多个Java方法调用dao mapper,在sql中写比较省事,毕竟只需要一次“参数检查”。
上面的写法是针对一个查询条件的,如果有多个查询条件,记得处理条件之间的关系,
比如 a=1 and b =2 or c=3.
如果有in条件,最好加上括号,(a=1) and (b =2 ) or ( c in ...)
http://images.cnitblog.com/blog/437282/201411/041405283617635.gif
萌萌的IT人
其他精彩文章文章
Android KSOAP2调用.net webservice
jQuery教程(8)-DOM树操作之使用反向插入方法
android学习笔记(34)使用AlertDialog创建简单对话框
android学习笔记(33)画廊视图(Gallery)的功能和用法
android navidgation drawer 在导航抽屉中如何改变List选中项的...
更多关于android开发文章
页:
[1]