我正在尝试使用 Jersey Library 构建一个 REST API。API 中的 Post 方法应该使用 JSON 正文。当我尝试通过 Postman 发送请求时,我收到 405 错误。@POST@Path("CreateADGroup")@Produces(MediaType.APPLICATION_JSON)@Consumes("application/json")@RequiredRight(value = "createADGroup")public Map postCreateADGroup(RequestValues requestValues) { log.debug("POST CreateADGroup"); log.debug("This is the value" + requestValues.getValue()); // using a test map untill i can get the actual values. Map ret = new HashMap(); ret.put("Val", "TestVal"); return ret;}这是POJO方法public class RequestValues {String value;public String getValue() { return value;}public void setValue(String value) { this.value = value;}}我曾尝试使用 Direct JsonObject 初始化,但我收到了同样的错误。@POST@Path("CreateADGroup")@Produces(MediaType.APPLICATION_JSON)@Consumes("application/json")@RequiredRight(value = "createADGroup")public Map postCreateADGroup(JSONObject requestValues) {Map ret = new HashMap(); ret.put("Val", "TestVal"); return ret; }
1 回答

沧海一幻觉
TA贡献1824条经验 获得超5个赞
是的,我想出了答案。我将方法签名更改为 Map。
@POST
@Path("CreateADGroup")
@Produces(MediaType.APPLICATION_JSON)
@Consumes("application/json")
@RequiredRight(value = "createADGroup")
public Map postCreateADGroup(Map requestValues) {
log.debug("POST CreateADGroup");
log.debug("This is the value" + requestValues.get("value"));
Map ret = new HashMap();
ret.put("Val", "No Val");
return ret;
}
添加回答
举报
0/150
提交
取消