ajax+post+json+@requestBody走天下
来源:互联网 发布:js控制标签显示隐藏 编辑:程序博客网 时间:2024/05/19 03:44
什么js对象,json对象,json字符串?它们又长什么样呢?
js对象:jsObj
json对象:jsonObj
json字符串:jsonString
ajax如何发post?
1:定义json对象
var obj = {"factoryId":Id};
2:写$.ajax$.ajax({
type:”POST”,
url: “/ASW/wxcurrent.html”,
data:JSON.stringify(jsonObj),
dataType: “json”,
contentType:”application/json”,
success:function(result){
console.log(success);
},
error:function(){
alert(“error”);
}
})
解释一波:ajax可以发送三种格式的请求+数据
:post+json字符串(最常用的方式):post+json对象:get+查询字符串
3.@requestBody接收json字符串
点击:Understanding @RequestBody
网上几乎博客的思路都是:在Java服务端见一个bean或java对象类,MappingJacksonHttpMessageConverter会将json数据转换成这个java对象来属性值。
官方对@requestBody的解释是:
(1)For access to the HTTP request body. Body content is converted to the declared method argument type using HttpMessageConverters.
(2)The @RequestBody method parameter annotation indicates that a method parameter should be bound to the value of the HTTP request body
看这个下面这个举例,可以知道可以直接获取基本数据类型String,并不是只可以获取引用类型(java对象)
比如:我要获取factortId的值,我的方法参数类型就得是拥有factortId属性的Factory类,
@RequestMapping(value = "/wxcurrent",method=RequestMethod.POST,consumes="application/json")@ResponseBodypublic void wxfactoryCur(@RequestBody Factory factory, HttpServletResponse response) { System.out.println("factory:"+factory); System.out.println("factoryId:"+factory.getFactoryId());}
Factory实体类
package cn.edu.hdu.Entity;public class Factory { private Integer factoryIndex; private Integer factoryId; private String systemName; private String pc_ph; private Integer modelNum; private Integer modelId; public Integer getFactoryIndex() { return this.factoryIndex; } public void setFactoryIndex(Integer factoryIndex) { this.factoryIndex = factoryIndex; } public Integer getFactoryId() { return this.factoryId; } public void setFactoryId(Integer factoryId) { this.factoryId = factoryId; } public String getSystemName() { return this.systemName; } public void setSystemName(String systemName) { this.systemName = systemName; } public String getPc_ph() { return this.pc_ph; } public void setPc_ph(String pc_ph) { this.pc_ph = pc_ph; } public Integer getModelNum() { return this.modelNum; } public void setModelNum(Integer modelNum) { this.modelNum = modelNum; } public Integer getModelId() { return this.modelId; } public void setModelId(Integer modelId) { this.modelId = modelId; }}
- ajax+post+json+@requestBody走天下
- AJAX-requestBody-提交JSON
- @RequestBody注解Ajax post json List集合数据请求400/415问题
- spring mvc @RequestBody接受post json对象
- spring mvc @RequestBody接受post json对象
- Maven项目:Spring MVC + Ajax + Json + RequestBody:POST后台服务器接收前端JSON数据并注解到POJO内
- ajax post json
- ajax post json
- 使用@RequestBody 取POST方式的json字符串
- jquery ajax post json对象
- ajax技术,json,xml,post
- ajax Post JSON与SpringMVC
- SpringSide4 @RequestBody接受post json对象 (415 Unsupported media type)
- SpringSide4 @RequestBody接受post json对象 (415 Unsupported media type)
- springMVC用@RequestBody接受post json对象 (415 Unsupported media type)
- spring boot get和post请求,以及requestbody为json串时候的处理
- SpringSide4 @RequestBody接受post json对象 (415 Unsupported media type)
- SpringMVC @RequestBody接受post json对象 (415 Unsupported media type)
- 【论文阅读】Illuminating Pedestrians via Simultaneous Detection & Segmentation
- 电商高复用购物车业务分析和代码实现
- Binary Search:162. Find Peak Element
- 【nginx】nginx与apache详细性能对比
- 获取从服务器传来的key-value对
- ajax+post+json+@requestBody走天下
- javascript各种设计模式
- 第二次自考总结
- JS跳出循环的三种方法(break, return, continue)
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Prefer
- 斯坦福机器学习笔记 第2周 五、Octave教程(一)
- Python视觉处理(四)HSV处理
- sublime VI编辑器 十分钟熟练掌握各种命令
- zlib库 在windows下的编译与使用