<MyBatis>前台传参为数组,后台SQ查询案例;

一般用于多选场景:多选查询;

如下图所示:

传值:"status" : ["保存","关闭"],

不传值:"status": [],

传给后台:

控制层:

java 复制代码
	@PostMapping(value = "/getList")
    @AuthInterceptor("mcg:getxxx:getList")
    public Result getList(HttpServletRequest request,@RequestBody String param) {
        try {
            Map<String, Object> paramMap = JsonUtils.readValue(param, Map.class);
            return Result.success().result(xxxService.getList(request,paramMap));
        } catch (Exception e) {
            log.error("XxxListController getList is error===:" + e.getMessage(), e);
            return Result.failure("据查询失败");
        }
    }
    

Mapper.xml层:

sql 复制代码
    <if test = "null != status and status.size > 0">
        and status in
        <foreach collection="status" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </if>
  	

疑问:

按理来说:前台传入的status 为数组类型,SQ 中if条件判断应该是:and status.length > 0,但是这样会报错,

所以最后选择:and status.size> 0;

欢迎给位大佬指点迷津!

相关推荐
fzb5QsS1p3 分钟前
MySQL 事务的二阶段提交是什么?
数据库·mysql
科雷软件测试33 分钟前
Python中itertools.product:快速生成笛卡尔积
开发语言·python
派大星~课堂3 小时前
【力扣-142. 环形链表2 ✨】Python笔记
python·leetcode·链表
Thomas.Sir3 小时前
第一章:Agent智能体开发实战之【初步认识 LlamaIndex:从入门到实操】
人工智能·python·ai·检索增强·llama·llamaindex
清风徐来QCQ3 小时前
Lombok/SSM/devTools
数据库
LaughingZhu3 小时前
Product Hunt 每日热榜 | 2026-04-05
前端·数据库·人工智能·经验分享·神经网络
2601_949814694 小时前
使用mysql报Communications link failure异常解决
数据库·mysql
搜佛说4 小时前
02-第2章-核心概念与架构
数据库·物联网·微服务·架构·边缘计算·iot
ZTL-NPU4 小时前
Jetbrains开发ros
ide·python·pycharm·编辑器·ros·clion
环黄金线HHJX.4 小时前
TSE框架配置与部署详解
开发语言·python