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

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 请问 springboot 如何接收 json 数组?比如根据 ID 批量删除?
未分類
22 7 月 2020

请问 springboot 如何接收 json 数组?比如根据 ID 批量删除?

请问 springboot 如何接收 json 数组?比如根据 ID 批量删除?

資深大佬 : Vimax 11

请问根据 ID 批量删除,前端传入的是 JSON 数组,比如

[1,2,3] 

传统在 URL 上传参是可以直接通过数组接收,但是通过 JSON 传参,则需要使用 @RequstBody 接收,但是接收的数据类型设置为什么呢?

前端在数组里面传对象,也可以接收

[{"id:1},{"id":2}] 

但是后端如何接收

[1,2,3] 

这样的 json 数据?

大佬有話說 (8)

  • 資深大佬 : xDaShen

    List<Integer>

  • 資深大佬 : magiclz233

    List<String>或者 List<Integer>, 里面传的是你的要删除的 id 集合, 如果是[{},{}]这种形式,List<Bean>

  • 資深大佬 : oneisall8955

    印象 @RequestBody int[] ids 可以好像,List<Intege> ids 外面需要包一层?
    具体忘记了(#-.-)

  • 資深大佬 : zhuawadao

    @JsonObject 试试可以吗

  • 資深大佬 : paragon

    RequestEntity<List<Long>> ids;
    ids.getBody();

  • 資深大佬 : ilumer

    这是 spring mvc,在 body 里面直接接收数组
    {
    private List<Long> ids;
    }
    https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-requestbody

  • 資深大佬 : EminemW

    你应该用 json 格式。。
    {
    “id”:[]
    }

  • 資深大佬 : cnzjl

    get 请求前端传递字符串用,分割, post 请求前端直接传递数组如:[1,2,3,4] ,直接 @RequestBody 就好了
    “`java
    @RequestMapping(value = “array”,method = RequestMethod.POST)
    @ResponseBody
    public String array(@RequestBody List<Integer> ids){
    return ids.toString();
    }
    “`

文章導覽

上一篇文章
下一篇文章

AD

其他操作

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

51la

4563博客

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