一般用于多选场景:多选查询;
如下图所示:
传值:"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;
欢迎给位大佬指点迷津!