当前位置: 首页 > 新闻动态 > 软件编程

浅谈springMVC接收前端json数据的总结

作者:用户投稿 浏览: 发布日期:2026-01-11
[导读]:下面小编就为大家分享一篇浅谈springMVC接收前端json数据的总结,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

对于json对象类型(即JsonObject)的数据,springMVC主要有以下几种方式接收:

1.通过Map接收

@RequestMapping(value = "/getAllStudio" )
  public void getAllStudio(@RequestBody Map<String, Integer> map ) {
    JSONObject json = new JSONObject();
    Integer page = map.get("page") ;// 当前页
    Integer rows = map.get("rows") ;// 每页显示的数量
    }

2.通过将数据封装在一个vo对象中来接收

@RequestMapping(value = "/addStudio")
public JSONObject addStudio(@RequestBody Studio stu) throws IOException {
  JSONObject json = new JSONObject();

  if(stu==null){

     json.put("result",false);
     return json;
  }
  }

补充:几种常见的post传输数据的方式

在传输http请求时,Content-Type 字段来获知请求中的消息主体是用何种方式编码

1.application/x-www-form-urlencoded

表单提交的方式,其传输的数据会被转换为data1=1&data2=2的形式。

在controller层可通过request.getParametre(“data1”);获取。

Ajax提交数据时,一般也采用该形式。

2.multipart/form-data

多文件上传时指定的格式。

3.application/json

以json格式传输数据。

这篇浅谈springMVC接收前端json数据的总结就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

免责声明:转载请注明出处:http://sczxchw.cn/news/334178.html

扫一扫高效沟通

多一份参考总有益处

免费领取网站策划SEO优化策划方案

请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!