目录
在xml中使用in查询需要使用foreach标签
- <foreach item="item" collection="list" index="index" open="(" separator="," close=")">
-
- #{item}
-
- foreach>
foreach的属性:
item:表示集合中每一个元素进行迭代的别名。
collection:为参数类型。
index:指定的名字,表示每次迭代的位置。
open:表示该语句以什么开始。
separator:表示在每次进行迭代时以什么符号为分隔符。
close:表示以什么结束
mapper:
List selectName(List;
xml:
- <select id="selectName" resultType="String">
-
- select name from sys_app where id in
-
- <foreach item="item" collection="list" index="index" open="(" separator="," close=")">
-
- #{item}
-
- foreach>
-
- select>
mapper:
List selectName(String[] ids);
xml:
- <select id="selectName" resultType="string">
-
- select name from sys_app where id in
-
- <foreach item="item" collection="array" index="index" open="(" separator="," close=")">
-
- #{item}
-
- foreach>
-
- select>
-
-
- List
list = new ArrayList<>(); - list.add(1);
- list.add(2);
- Map
map =new HashMap<>(); - map.put("ids",list);
- map.put("parms","sss");
mapper:
List<String> selecyName(Map map);
xml:
- <select id="selectName" resultType="String">
-
- select name from sys_app where id in
-
- <foreach item="item" collection="ids" index="index" open="(" separator="," close=")">
-
- #{item}
-
- foreach>
-
- select>
对象:
- @Data
- @ApiModel(value = "user",description = "用户BO")
- public class UserBo extends BaseEntity {
-
- @ApiModelProperty(value = "id")
- private Integer id;
-
- @ApiModelProperty(value = "姓名")
- private String name;
-
- @ApiModelProperty(value = "年龄")
- private Integer age;
-
- @ApiModelProperty(value = "性别")
- private String sex;
-
- private List
ids; -
- }
mapper:
List getInfoList(@Param("query") UserBo bo);
xml:
- <select id="getInfoList" resultType="com.system.domain.vo.UserVo">
- select *
- from user
- where is_del = 0
- <if test="query.ids != null">
- and id in
- <foreach item="item" collection="query.ids" index="index" open="(" separator="," close=")">
- #{item}
- foreach>
- if>
- select>
符号 | 原符号 | 替换符号 |
---|---|---|
小于 | < | < |
小于等于 | <= | <= |
大于 | > | > |
大于等于 | >= | >= |
不等于 | <> | <> |
与 | & | & |
单引号 | ' | &apos |
双引号 | " | " |