How to deal with the JSON value sent from the front end using the String type in the back end

1. Receive with @RequestParam

    @PostMapping("ccc1")
    public String ccc1(@RequestParam("name") String name) {
        return name;
    }

    2. Receive in the form of entity class

    @PostMapping("ccc2")
    public String getList(@RequestBody TestUser user) {
        return "success";
    }

    3. Receive with map

    @PostMapping("ccc")
    public boolean ccc3(@RequestBody Map<String,Object> map) {
        if (map.containsKey("name")){
            String name = map.get("name").toString();
            boolean b = testUserService.selectAllByName(name);
            return b;
        }else {
            return false;
        }
    }


    4. When List receives
    such a json array from the front end: [{id, username, password}, ​​{id, username, password},    
    ​​{id, username, password},...], use List<E> to receive it

    @PostMapping("getList")
    public String getList(@RequestBody List<TestUser> list) {
        for (TestUser user : list) {
            System.out.println(user.toString());
        }
        return "success";
    }

Guess you like

Origin blog.csdn.net/qq_42514371/article/details/126158837