Required String parameter 'id' is not present

问题详情:

      简单的说,我就是通过ajax发起了一个post请求到后台,但是后台没有收到请求发过去的参数,并且还报了这样的错误。

      错误描述告诉我们,请求参数里面并没有存在id。我检查的浏览器的请求,确实有带参数,拼写无误。

      那么,必然就是接收方式出错了,参数错误或者是post请求不能这么接收。

  前端页面,发起Ajax请求,请求方式为post。

$.ajax({ 
    url: "test/test", 
    type:"POST"
data:'{"id":"1111","date":"2018"}', success: function(){ ..... }});

      后端代码,接收方式为@ PostMapping("/test"),@RequestParam

    @GetMapping("/test")
    @RequiresPermissions({"test"})
    @ResponseBody
    public TableDataInfo test(@RequestParam String id,@RequestParam String date)
    {
      ......
    }    

解决方案:

       1、将后台代码的 @RequestParam 改为@RequestBody

             测试后发现有问题,报错。

   相关参考

  2、干脆不用post请求,改为get,亲测有效。

          相关参考  

原文地址:https://www.cnblogs.com/liuyp-ken/p/10043038.html