Not rigorous writing, may be error: in (), this situation does not conform to the MySQL syntax.
Select from Loanwhere loan_id in
<foreach item= "item" index= "id" collection= "list" open= "(" separator= "," close= ")" >
#{item}
Either in a MyBatis SQL file or in a Java program.
The syntax in SQL :
<select id= "Findbyloanids" parametertype= "List" >
SELECT *
from p2p_loan_variation where 1 = 1
<if test= "List! = null and list.size>0" >
and loan_id in
<foreach item= "item" index= "id" collection= "list" open= "("
separator= "," close= ")" >
#{item}
</foreach>
</if>
<if test= "list==null or list.size==0" >and 1=0</if>
</select>
what to do in Java:
list<loanvariation> List = null;
if (Listutils.isnotempty (loadids) {
list =loanvariationdao.findbyloanids (loanids);
}
return list;
If there are multiple Java methods calling DAO Mapper, it is easier to write in SQL, after all, only one "parameter check" is required.
The above wording is for a query condition, if there are multiple query conditions, remember to deal with the relationship between the conditions,
such as a=1 and B =2 or c=3.
If there is an in condition, it is best to add parentheses, (a=1) and (b =2) or (c in ...).
650) this.width=650, "src=" http://images.cnitblog.com/blog/437282/201411/041405283617635.gif "width="/>
Moe's IT People
In the SQL statement in the MyBatis query, be sure to determine the condition of NULL