最近做app,使用mui的ajax给后台传参,后台一直接收不到值,表示很蛋疼。这里通过网上搜索加上个人实践,总结归纳了三种前端传值和后台接收的方式。

第一种:

  前端:

    data: JSON.stringify({username: 'username',password: 'password'}),

        headers: {'Content-Type': 'application/json'}

  后台:

    public String test1(@RequestBody Map<String, String> reqMap) {}

第二种:

  前端:

    }),

    headers: {

      'Content-Type': 'application/x-www-form-urlencoded'
    }

  后台:

    

第三种:

  前端:

    data: 'username=username&password=password',

    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }

  后台:

    public String tt(String username, String password) {}

相关文章: