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;
相关推荐
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ16 小时前
mapper.xml sql动态表查询配置
xml·java·sql
l1t1 天前
DeepSeek辅助利用搬移底层xml实现快速编辑xlsx文件的python程序
xml·开发语言·python·xlsx
ss2732 天前
手写Spring第4弹: Spring框架进化论:15年技术变迁:从XML配置到响应式编程的演进之路
xml·java·开发语言·后端·spring
Lucky_Turtle4 天前
【Java Xml】dom4j写入XML
xml·java·python
莫陌尛.4 天前
xml方式bean的配置---实例化bean的方式
xml
六元七角八分5 天前
pom.xml
xml·数据库
郑重其事,鹏程万里6 天前
commons-digester3(XML解析框架)
xml·java
七牛云行业应用6 天前
实战GPT-5:用“XML三明治”和“完美循环”重构你的提示
xml·gpt·重构
跌入凡尘的张公子6 天前
通过hutool生成xml
xml
optimistic_chen6 天前
【Java EE进阶 --- SpringBoot】Mybatis操作数据库(基础二)
xml·数据库·spring boot·笔记·java-ee·mybatis