POST请求接收数据
Post请求提交的参数类型
我自己常遇到的:
Content-Type:multipart/form-data(用于在表单中上传文件)
Content-Type:application/x-www-form-urlencoded(浏览器原生的form表单类型,不能上传文件)
Content-Type:application/json(以json形式进行传输,通常是传输对象时使用)
不常遇到的:
Content-Type:application/xml
Content-Type:application/javascript
Content-Type:text/plain
Content-Type:text/html
1.使用常规ajax或者$.post()。(浏览器原生 typr=application/x-www-form-urlencoded)
$.post()方法是jquery本身对ajax的一个简单封装,其效果等价于:
$.ajax({
url:url,
type:"POST",
data:data,
dataType:dataType,
success:function(data){
//success
}
});
$.post()函数有四个参数:URL、data、success、dataType,分别是
URL:请求的路径,对应ajax中的url
data:请求数据(可选)
success:请求成功之后执行的函数(可选)
dataType:请求成功之后返回的数据类型(可选)
如下例子:
$.post("/loginController/login","id=1",function(data){
//返回的JSON数据
},"json")
例如http://localhost:8080/CLSX2023/policy/info/reprintPdf
前端
reprintPdf :function (){
var bufaStartTime = vm.bufaStartTime;
var bufaEndTime = vm.bufaEndTime;
if(bufaStartTime==null||bufaEndTime==null){
alert("请选择补发时间起止!!")
return;
}
//location.href=projectPath()+"/policy/info/reprintPdf?bufaStartTime="+bufaStartTime+"&bufaEndTime="+bufaEndTime;
$.post(
projectPath()+"/policy/info/reprintPdf",
{"bufaStartTime":bufaStartTime,bufaEndTime:"bufaEndTime","Str":"666"},
function(data){
console.log(data)
},"json"
)
},
可以在浏览器查看
使用@RequestParam("Str")String str或者request.getParameter();这两个是一个意思不通过写法
@SysLog("补发清单下载")
@RequestMapping("/reprintPdf")
public void reprintPdf(HttpServletRequest request ,HttpServletResponse response, @RequestParam("Str")String str){
String bufaStartTime = request.getParameter("bufaStartTime");
String bufaEndTime = request.getParameter("bufaEndTime");
}
2.post请求使用multipart/form-data(用于在表单中上传文件)
2.1不使用注解
posMan中
后端
2.2使用注解
3.Content-Type:application/json格式参数
当传递的是json的时候用对象接收
get请求接收数据
参考↓
原文链接:https://blog.csdn.net/LoveStady/article/details/126620922