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

欢迎给位大佬指点迷津!

相关推荐
冬奇Lab4 小时前
每日一个开源项目(第134篇):Zvec - 阿里开源的嵌入式向量数据库,向量搜索界的 SQLite
数据库·人工智能·llm
hboot4 小时前
AI工程师第二课 - 数据处理
人工智能·python·数据分析
用户8356290780518 小时前
使用 Python 自动化 PowerPoint 形状布局与格式设置
后端·python
用户83562907805110 小时前
用 Python 自动化 PowerPoint 演讲者备注添加
后端·python
ClouGence14 小时前
Oracle CDC 架构优化:从主库直连到 DataGuard 备库同步
数据库·后端·oracle
黄忠16 小时前
01-系统架构设计-LangGraph状态机与多源异构RAG
python
zzzzzz31016 小时前
假如我是掘金管理员,我先给评论区装个'代码审查'系统
python·程序员·机器人
无响应de神16 小时前
三、用户与权限管理
数据库·mysql
砍材农夫16 小时前
python环境|conda安装和使用(2)
后端·python