AJAX 数据传输 页面跳转

通用

function submit(val) {
   var dataObj = {};
   dataObj.departGuid = $("#departGuid").val();
   dataObj.states = 0;
   $.ajax({
      url: ctx + "beforehand/wholeDepartment/submit",
      type: "post",
      data: JSON.stringify(dataObj),
      dataType: "json",
      contentType: 'application/json',
      success: function (result) {
	  $.modal.alertSuccess('提交审核成功,下一步' + nextStatesName);
      error: function () {
          $.modal.alertWarning("操作失败");
      }
   });
}
@PostMapping("/evaluationSubmit")
@ResponseBody
public AjaxResult evaluationSubmit(@RequestBody WholeDepartment wholeDepartment) {
   return wholeDepartmentService.evaluationSubmit(wholeDepartment);
}

传输方式一,只有一个参数get (@PathVariable)

  1. JS
updateUrl: prefix + "/edit/{id}",

ctx + "beforehand/evaluationInfo/export1/" + id
  1. 控制器
@GetMapping("/edit/{evaluationTargetCompletionGuid}")
 public String edit(@PathVariable("evaluationTargetCompletionGuid") String evaluationTargetCompletionGuid, ModelMap mmap)

传输方式二,多个参数get (@RequestParam)

访问路径

http://localhost:8071/direct?msg=%27%E5%95%8A%E5%95%8A%E5%95%8A%27&code=6

控制器

@GetMapping("/direct")
public String sendEmail(@RequestParam Map<String,Object> params){
    String msg = params.get("msg").toString();
    rabbitTemplate.convertAndSend("EmailExchange","EmailRoutingKey",msg);
    return "OK";
}

传输方式三,只有一个参数 post

  1. JS
function fileDown(path){
	 $.ajax({
	 	 url: ctx + "beforehand/projectFile/fileDown?filePath="+path,
           	 type: "post",
           	 success: function (result) {
                	 alert('控制器成功');
         	 },
         	 error: function () {
                	alert("控制器错误");
            	}
          });
}
  1. 控制器
public String Down( String filePath) {

传输方式四 Post dataObj

  1. JS
function fileDown(path){
        dataObj = {};
        dataObj.filePath = path;
        $.ajax({
            url: ctx + "beforehand/projectFile/fileDown",
            type: "post",
            data: JSON.stringify(dataObj),
            dataType: "json",
            contentType: 'application/json',
            success: function (result) {
                alert('控制器成功');
                 },
            error: function () {
                alert("控制器错误");
            }
        });
 }
  1. 控制器
public String Down( @RequestBody ProjectFile projectFile ) {

@RequestParam和@RequestBody的区别

由于spring的RequestParam注解接收的参数是来自于requestHeader中,即请求头,也就是在url中,格式为xxx?username=123&password=456,而RequestBody注解接收的参数则是来自于requestBody中,即请求体中。

传数组

后端用数组类型接收

前端:http://localhost:8591/api/promotion/push/pickcenter/1,3

@PostMapping("/pickcenter/{useType}")
public ResponseEntity<Map> pickcardcenter(@PathVariable("useType") int[] useTypeArray){

你可能感兴趣的:(笔记)