<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;

欢迎给位大佬指点迷津!

相关推荐
Jamesvalley2 分钟前
【Django】新增字段后兼容旧接口 This field is required
后端·python·django
Luck_ff081031 分钟前
【Python爬虫详解】第四篇:使用解析库提取网页数据——BeautifuSoup
开发语言·爬虫·python
拿破轮34 分钟前
查询Hologres或postgresql中的数据
数据库·postgresql
学渣6765639 分钟前
什么时候使用Python 虚拟环境(venv)而不用conda
开发语言·python·conda
爱的叹息1 小时前
Spring和Spring Boot集成MyBatis的完整对比示例,包含从项目创建到测试的全流程代码
spring boot·spring·mybatis
悲喜自渡7211 小时前
线性代数(一些别的应该关注的点)
python·线性代数·机器学习
Huanzhi_Lin2 小时前
python源码打包为可执行的exe文件
python
声声codeGrandMaster2 小时前
django之账号管理功能
数据库·后端·python·django
Elastic 中国社区官方博客2 小时前
使用 LangGraph 和 Elasticsearch 构建强大的 RAG 工作流
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
AscendKing2 小时前
mongo客户端操作mongodb记录
数据库·mongodb