case

{host}/kb/query/knowledge/audit/list?contentSrc=xhs&contentType=weng&id=&status=&dataSrc=xhs&pageNum=1&pageSize=10&modifyUid=&mtime[]=2024-01-02 00:00:00&mtime[]=2024-02-16 00:00:00&path=knowledgeReview

方法:用 RequestParam手动指定数组 key

public ResultWrapper<PageInfo<KnowledgeAuditResultDTO>> queryKnowledgeAuditList(@RequestParam(name = "mtime[]",  required = false) List<String> mtime, @RequestParam Map<String, String> params) {

此时,直接 Postman模拟请求Java 服务

{host}/kb/query/knowledge/audit/list?mtime[]=2024-01-02 00:00:00&mtime[]=2024-02-16 00:00:00&path=knowledgeReview

会提示失败,因为[]是特殊字符。

通过 Vue+Node 调用,没问题。看代码,Node 层做了编码

const url = uri + '?' + qs.stringify(query);

编码后

<http://127.0.0.1:9991/kb/query/knowledge/audit/list?contentSrc=xhs&contentType=weng&id=&status=&dataSrc=xhs&pageNum=1&pageSize=10&modifyUid=&mtime%5B%5D=2024-01-02%2000%3A00%3A00&mtime%5B%5D=2024-02-16%2000%3A00%3A00&path=knowledgeReview>

Spring支持

实际上,Spring支持直接用String[]来接收ids=1,2,3

   //都可以
    //curl '<http://127.0.0.1:18080/array?ids=1,2,3>'
    //curl '<http://127.0.0.1:18080/array?ids=1&ids=2&ids=3>'
    @GetMapping("/array")
    public String testArray(@RequestParam("ids") String[] ids) {
        return Arrays.toString(ids);
    }

See:https://github.com/lunaczp/java/blob/master/hello-spring-web/src/main/java/com/lunac/learning/java/demo/controller/HelloController.java