目录

后端如何接受前端传过来的Json数据

后端如何接受前端传过来的Json数据

后端如何接受前端传过来的Json数据

这里只讲解一些最常用的,最好用的方式

对于参数较少的,我们可以

使用@RequestParam

 @RequestMapping("/testJson2")
    @ResponseBody
    public String testJson2(@RequestParam String username,@RequestParam String password){
        System.out.println(username);//hahah
        System.out.println(password);//123456
        return "aaaa";
    }

对于参数较多的

同样也是使用@RequestParam,参数类型使用Map

     @RequestMapping("/modifyName")
    @ResponseBody
   
    public ResponseResult modify1(@RequestParam Map map) {
    	//这里获取什么数据拒绝于你前端传递的数据
         System.out.println( map.get("id"));   
        return ResponseResult.success();
    }

也可也使用对象进行接受,但是前提是参数必须保持一致。

 @RequestMapping("/modifyName")
    @ResponseBody
    public ResponseResult modify1(User user) {
    	 //直接用get set 获取你要的数据就行
        return ResponseResult.success();
    }