SpringMVC cannot map an array in an object

there is an object in the background

Class Code {
    private List<String> data;
    private int msg;
}

controller

public Object test(@ModelAttribute Code code)

the front end submits data to the background

$.get("http://xxxxx",{
    data: ["123","123"],
    msg: "121313"
},)

background cannot map data to data

Mar.25,2021

the backend interface is received with @ RequestBody , and then the front end is submitted in json format


positive solution upstairs, change it to

public Object test(@RequestBody Code code)

pay attention to the header application/json when submitting the front end

Menu