xml中in的使用

目录

一、简介

 二、使用

1、参数为list

2、参数为Array

3、参数为Map

4、参数为对象(集合在对象中)

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


一、简介

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

<foreach  item="item" collection="list" index="index"  open="(" separator="," close=")">

			#{item}

</foreach>

foreach的属性:

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

collection:为参数类型。

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

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

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

close:表示以什么结束

 二、使用

1、参数为list

mapper:

List<String>  selectName(List<Object> ids);

 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:

List<String>  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>


3、参数为Map

 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:

List<String> selecyName(Map<String,Object> 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>

4、参数为对象(集合在对象中)

对象:

@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<Integer> ids; 

}

mapper:

List<UserVo> 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>

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

符号原符号替换符号
小于<&lt;
小于等于<=&lt;=
大于>&gt;
大于等于>=&gt;=
不等于<>&lt;&gt;
&&amp;
单引号'&apos
双引号"&quot;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值