我正在尝试将查询字符串转换为 Pojo。有没有办法将查询字符串转换为 pojo.以下是我到目前为止所尝试过的:
请求:
POST /Service/services/handler/qpStringtoPOJO HTTP/1.1
Host: localhost
Cache-Control: no-cache
id=123434&value=BB$@##@FDBB$#Gw3r3232rvd
Pojo:
package com.nexsols.license.model;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Pojo {
String id;
String value;
@XmlElement(name="id")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@XmlElement(name="value")
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public String toString() {
return "Pojo [id=" + id + ", value=" + value + "]";
}
}
服务方式:
@POST
@Path("/qpStringtoPOJO")
public String qpStringtoPOJO(@QueryParam("") Pojo pojo){
System.out.println(pojo);
return "SUCCESS";
}
当前输出为 Pojo [id=null,value=null]
我正在使用 cxf 进行服务。我做错了什么吗? 提前致谢。
最佳答案
您还可以使用 map 并从 request.getParameterMap() 获取它。 然后您可以将所需的键传递给该映射以获取它们的值。
关于java - 如何在cxf java中将查询字符串反序列化为pojo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26959906/