博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ajax提交JSON数组及Springboot接收转换为list类
阅读量:2388 次
发布时间:2019-05-10

本文共 731 字,大约阅读时间需要 2 分钟。

1、AJAX传递JSON数据

    
Title
@RequestMapping(value="/save",method = RequestMethod.POST,consumes = "application/json")    @ResponseBody    public String save(@RequestBody XxxBean bean){        System.out.println(bean);        return "success";    }

2、AJAX传递JSON数组

    
Title

不能直接使用JSONArray类型的参数接收前台的json数组字符串。曲线救国:用JSONObject接收,然后取出JSONArray。

@RequestMapping(value="/saveAll",method = RequestMethod.POST,consumes = "application/json")    @ResponseBody    public String saveAll(@RequestBody JSONObject jsonObject){        JSONArray jsonArray = jsonObject.getJSONArray("beans");        List
list=(List)JSONArray.toCollection(jsonArray,XxxBean.class); xxxService.saveAll(list); return "successAll"; }

转载地址:http://kwtab.baihongyu.com/

你可能感兴趣的文章
使用Apache Common的FileUpload的一点点注意事项
查看>>
arduino连接热敏打印机的资料
查看>>
用zxing生成条形码
查看>>
如何将OpenShift与eclipse集合使用
查看>>
Build Your Own PaaS on RHEL 6
查看>>
关于JAX-RS的导引阅读
查看>>
Markdown编辑器editor.md的使用
查看>>
FileServlet supporting resume and caching and GZIP
查看>>
spring boot etag header example
查看>>
关于大数据的两个大分支
查看>>
spring boot Websocket
查看>>
关于企业到个人的转账
查看>>
Angular4中调用js代码
查看>>
JAVA8-用lamda表达式和增强版Comparator进行排序
查看>>
spring boot 2.0 使用Hikari连接池——号称java平台最快的,替换druid
查看>>
GnuPG Java Wrapper API - Sample code
查看>>
HTTP Cache 总结及Nginx Cache配置
查看>>
基于现有 TensorFlow 模型构建 Android 应用
查看>>
Building an Ionic OCR App with Tesseract
查看>>
Spring boot with Apache Hive
查看>>