跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 大哥们, springboot RestTemplate 的 exchange delete 可以传递 list 为参数吗
未分類
27 3 月 2021

大哥们, springboot RestTemplate 的 exchange delete 可以传递 list 为参数吗

大哥们, springboot RestTemplate 的 exchange delete 可以传递 list 为参数吗

資深大佬 : liian2019 0

接口是这样的

    @DeleteMapping     @ApiOperation("删除数据")     public R<Boolean> delete(@RequestParam("idList") List<Long> idList) {         return success(this.jobJdbcDatasourceService.removeByIds(idList));     } 

我的调用方式是这样的

@Override     public void deleteDataSource(List<String> ids) {         if (CollectionUtils.isEmpty(ids)){             return;         }         List<Long> datasourceIds =       ids.stream().map(Long::parseLong).collect(Collectors.toList());         MultiValueMap<String,Object> params = new LinkedMultiValueMap<>();         params.add("idList",datasourceIds);         HttpEntity<MultiValueMap<String,Object>> entity = new HttpEntity<>(params,new HttpHeaders());         ResponseEntity<DataXResponse> exchange = restTemplate.exchange(adminServer + dataSourcePath,HttpMethod.DELETE,entity,DataXResponse.class);         boolean isSuccess = this.handleResponse(exchange,Boolean.class);         if (!isSuccess){             throw new FastdataException(FastdataPlatErrorCode.REST_CALL_FAILED.getCode(),"删除失败");         }     } 

然后服务端报错了

Caused by: java.lang.NumberFormatException: For input string: "[12]" 

意思就是需要一个 list,但是接受到一个 string

有大哥遇到过这样的情况吗

大佬有話說 (6)

  • 資深大佬 : ouyc

    试试传一个用 , 隔开的字符串表示的 list

  • 資深大佬 : hantsy

    标准的 Uri 这种参数传递应该都是支持三种格式的。

    1. uri?a=1&a=2&a=3
    2. uri?a=1,2,3
    3. uri?a[]=1&a[]=2&a[]=3

    如果你的生成 URI 不是的话,肯定会有问题。

  • 資深大佬 : hantsy

    找到了一个我的例子:

    https://github.com/hantsy/spring-webmvc-jwt-sample/blob/master/src/test/java/com/example/demo/VehicleControllerTest.java#L73

  • 主 資深大佬 : liian2019

    @ouyc 还真是,这是什么原理大佬

  • 主 資深大佬 : liian2019

    @hantsy 好的 谢谢你

  • 主 資深大佬 : liian2019

    @hantsy 谢谢大佬

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具