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 ...).
In the SQL statement in the MyBatis query, be sure to determine the condition of NULL