zoukankan      html  css  js  c++  java
  • Restful传递数组参数的两种方式

    第一种,直接传递数组

    • js直接传递数组
    var data = ["123","456"];
    that.loadDictionarys(data).subscribe({ next: res => { }, error: err => { } });
    • 后端接口直接接收数组
    @POST
        @Path("/loadDictionarys")
        @Produces({ MediaType.APPLICATION_JSON, FastJSONProvider.TEXT_JSON, FastJSONProvider.TEXT_FASTJSON })
        public RestResponse loadDictionarys(String[] dicItemCodeArr) {
                Map<String, DictionaryVO> dictionaryVOs = new HashMap<>();
                RestResponse successResult = RestResponse.successResult(dictionaryVOs);
                return successResult;
        }

    第二种,通过json对象传递

    • js组装json对象传递数组
    var data = {
      arr:["123","456"]
    };
    that.loadDictionarys(data).subscribe({
        next: res => {      
        },
        error: err => {
        }
    });
    • 后端接口通过@FormParam注解可用String集合接收
    @POST
        @Path("/loadDictionarys")
        @Produces({ MediaType.APPLICATION_JSON, FastJSONProvider.TEXT_JSON, FastJSONProvider.TEXT_FASTJSON })
        public RestResponse loadDictionarys(@FormParam("arr") List<String> arr) {
                Map<String, DictionaryVO> dictionaryVOs = new HashMap<>();
                RestResponse successResult = RestResponse.successResult(dictionaryVOs);
                return successResult;
        }
  • 相关阅读:
    Redis教程_2
    Redis教程_1
    机器学习概念_2
    机器学习概念_1
    [极客大挑战 2019]LoveSQL
    [极客大挑战 2019]EasySQL
    [SUCTF 2019]EasySQL
    [强网杯 2019]随便注
    [HCTF 2018] WarmUp
    php代码函数笔记
  • 原文地址:https://www.cnblogs.com/meng-ma-blogs/p/10552727.html
Copyright © 2011-2022 走看看