关于mui前端传值,springboot后台接收值的问题

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

第一种:

  前端:

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

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

  后台:

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

第二种:

  前端:

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

    headers: {

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

  后台:

    public void test(@RequestParam(value="params") Map<String, String> map) {}

第三种:

  前端:

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

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

  后台:

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

posted @ 2019-04-03 23:15  神级尘埃  阅读(3973)  评论(0编辑  收藏  举报