How to use in in Mybatis query SQL?

Here is a demo that only passes one parameter, which is an array of strings.

Here foreach dynamic statement,

Parameters of foreach:

The attributes of the foreach element mainly include item, index, collection, open, separator, and close.

item represents the alias of each element in the collection when iterating.

index specifies a name used to indicate the position to which each iteration goes during the iteration.

The parameters passed in the collection.

open indicates what the statement starts with, and separator indicates what symbol is used as the separator between each iteration.

close means what to end with.

xml is as follows

<select id="getList" resultType="Student">

        select * from student a 

       where a.del_flag='0' and a.name in

        <foreach item="item" index="index" collection="nameArray"  open="(" separator="," close=")">
                #{item}
        </foreach>

 </select>

The corresponding Java interface is as follows:

List<DataStandard> getListByFileName(@Param(value="nameArray") String[] nameArray);   


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325920184&siteId=291194637