前端页面传参后端接收

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

  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值