浅谈springMVC接收前端json数据的总结
发布时间:2020-12-14 19:52:54 所属栏目:Java 来源:网络整理
导读:对于json对象类型(即JsonObject)的数据,springMVC主要有以下几种方式接收: 1.通过Map接收 @RequestMapping(value = "/getAllStudio" ) public void getAllStudio(@RequestBody MapString,Integer map ) { JSONObject json = new JSONObject(); Integer pag
对于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数据的总结就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程小技巧。 您可能感兴趣的文章:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |