xml中in的使用

目录

一、简介

二、使用

1、参数为list

2、参数为Array

3、参数为Map

XML中大于、小于、不等于符号使用


一、简介

在xml中使用in查询需要使用foreach标签

XML 复制代码
<foreach  item="item" collection="list" index="index"  open="(" separator="," close=")">

			#{item}

</foreach>

foreach的属性:

item:表示集合中每一个元素进行迭代的别名。

collection:为参数类型。

index:指定的名字,表示每次迭代的位置。

open:表示该语句以什么开始。

separator:表示在每次进行迭代时以什么符号为分隔符。

close:表示以什么结束

二、使用

1、参数为list

mapper:

java 复制代码
List<String>  selectName(List<Object> ids);

xml:

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>

2、参数为Array

mapper:

java 复制代码
List<String>  selectName(String[] ids);

xml:

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>

3、参数为Map

java 复制代码
 List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        Map<String,Object> map =new HashMap<>();
        map.put("ids",list);
        map.put("parms","sss");

mapper:

XML 复制代码
List<String> selecyName(Map<String,Object> map);

xml:

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>

XML中大于、小于、不等于符号使用

符号 原符号 替换符号
小于 < &lt;
小于等于 <= &lt;=
大于 > &gt;
大于等于 >= &gt;=
不等于 <> &lt;&gt;
& &amp;
单引号 ' &apos
双引号 " &quot;
相关推荐
IT_Octopus2 天前
一次由 RestTemplate 引发的 Connection reset:被 XML 截胡的请求体
xml·java·spring boot
Dontla2 天前
网站爬虫控制策略介绍(robots.txt、sitemap.xml、x-robots-tag、noindex、nofollow)网站索引
xml·爬虫·dubbo
风起洛阳@不良使3 天前
spring中xml和注解开发的对比
xml·java·spring
Mikowoo0074 天前
批量汇总XML格式的发票信息
xml·python
逃逸线LOF4 天前
xml文件如何加载properties文件(spring容器加载properties文件)
xml
前网易架构师-高司机7 天前
带标注的山体滑坡塌方数据集数据集,识别率78.1%,974张图,支持yolo,coco json,voc xml,文末有模型训练代码
xml·yolo·json·数据集·自然灾害·山体滑坡
程序媛kelly7 天前
.xml / .jrxml 文件怎么打开?OpenFiles 实测预览、编辑、搜索与 AI 摘要排查流程
xml·人工智能·jrxml
潘潘的嵌入式日记7 天前
改完Keil工程文件被缓存覆盖?——uvprojx编辑的进阶四坑
xml·嵌入式·keil·调试·mdk·工程文件
Full Stack Developme7 天前
Flowable XML标签大全
xml
C137的本贾尼8 天前
第九篇:微服务与分布式——把一个大系统拆成多个小服务
xml·spring boot·后端