gpt4 book ai didi

java - [ Spring ] : Request mapping nested Json with array inside it

转载 作者:太空宇宙 更新时间:2023-11-04 11:31:24 25 4
gpt4 key购买 nike

我有一个请求主体,

 {
"first": "0",
"second": "3",
"third": {
"Types": ["AAA"],
"Name": "XXXX"
}
}

我无法使用 spring 将其映射到请求映射。我尝试了下面的方法,但没有成功。

公共(public)类 requestMap {

private Integer skip;
private Integer take;
private Map<String, String[]> keywords;

public Integer getSkip() {
return skip;
}

public void setSkip(Integer skip) {
this.skip = skip;
}

public Integer getTake() {
return take;
}

public void setTake(Integer take) {
this.take = take;
}

public Map<String, String[]> getKeywords() {
return keywords;
}

public void setKeywords(Keywords keywords) {
this.keywords = (Map<String, String[]>) keywords;
}

}

如何映射请求正文?

编辑Json 中区分大小写的键。

最佳答案

这应该是正确的模型。

public class jsonObject
{
private Keywords keywords;

private String take;

private String skip;

public Keywords getKeywords ()
{
return keywords;
}

public void setKeywords (Keywords keywords)
{
this.keywords = keywords;
}

public String getTake ()
{
return take;
}

public void setTake (String take)
{
this.take = take;
}

public String getSkip ()
{
return skip;
}

public void setSkip (String skip)
{
this.skip = skip;
}

@Override
public String toString()
{
return "ClassPojo [keywords = "+keywords+", take = "+take+", skip = "+skip+"]";
}
}

//keywords class

public class Keywords
{
private String name;

private String[] types;

public String getName ()
{
return name;
}

public void setName (String name)
{
this.name = name;
}

public String[] getTypes ()
{
return types;
}

public void setTypes (String[] types)
{
this.types = types;
}

@Override
public String toString()
{
return "ClassPojo [name = "+name+", types = "+types+"]";
}
}

关于java - [ Spring ] : Request mapping nested Json with array inside it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43735249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com