Spring 将JSON数组传递给视图

Spring 将JSON数组传递给视图,spring,Spring,如何从请求API得到的JSON数组中列出视图中的值?我使用的是SpringMVC和thymeleaf,您可以使用annotation@RequestBody获取jsonArray,并使用一个具有模型列表的包装器来存储您的列表。 例如: 型号: public class Tuple { private String key; private String value; private String description; public String getKey() { return k

如何从请求API得到的JSON数组中列出视图中的值?我使用的是SpringMVC和thymeleaf,您可以使用annotation@RequestBody获取jsonArray,并使用一个具有模型列表的包装器来存储您的列表。 例如:

型号:

public class Tuple {
private String key;
private String value;
private String description;
public String getKey() {
    return key;
}
public void setKey(String key) {
    this.key = key;
}
public String getValue() {
    return value;
}
public void setValue(String value) {
    this.value = value;
}
public String getDescription() {
    return description;
}
public void setDescription(String description) {
    this.description = description;
}

public Tuple(String key, String value, String description) {
    this.key = key;
    this.value = value;
    this.description = description;
}
}

包装器:

public class TupleWrapper{
    private List<Tuple> tupleList;
    public List<Tuple> getTuple() {
        return tupleList;
    }
    public void setTuple(List<Tuple> tuples){
        this.tupleList = tuples;
    }
}
公共类TupleWrapper{
私有列表元组列表;
公共列表getTuple(){
返回元组列表;
}
公共void集合元组(列表元组){
this.tupleList=元组;
}
}
控制器:

@RequestMapping(value="/setTuple", method = RequestMethod.POST)
public ResponseEntity<ResponseStatus> setTuple(@RequestBody TupleWrapper wrapper){
    //your logic.
    return new ResponseEntity<ResponseStatus>(new ResponseStatus<>(STATUS.SUCCESS,"OK",wrapper),HttpStatus.OK);

}
@RequestMapping(value=“/setTuple”,method=RequestMethod.POST)
公共响应属性setTuple(@RequestBody-TupleWrapper-wrapper){
//你的逻辑。
返回新的ResponseEntity(新的ResponseStatus(STATUS.SUCCESS,“OK”,wrapper),HttpStatus.OK);
}