在我的jersey rest服务中,我试图创建一个实体标记,其中包含:
String content = 12sdfs-345dsdfsdf-231yscysd;
String createdContent = create(content);
return Response.created(createdUri).entity(createdContent).build();
就像写在泽西岛的文件一样。但是
createdContent
就是null
。怎么了?完整代码是:
@POST
@Consumes("application/x-www-form-urlencoded")
public Response postObject(@FormParam("number") int number) {
ObjectDTO c = new ObjectDTO();;
c.setNumber(number);
String generatedId = generateID();
c.setId(generatedId);
c.setOwner(sec.getUserPrincipal().getName());
return postAndGetResponse(c);
}
private Response postAndGetResponse(ObjectDTO object) {
Response res;
System.out.println(object);
if(ObjectDAO.instance.getObjectDao().containsKey(object.getId())) {
res = Response.serverError().status(409).build();
} else {
System.out.println(object);
System.out.println(object.getId());
String createdContent = create(object.getId());
System.out.println(createdContent);
res = Response.created(uriInfo.getAbsolutePath()).entity(createdContent).build();
ObjectDAO.instance.getObjectDao().put(object.getId(), object);
}
return res;
}
编辑:
http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e188
第2.5章
最佳答案
要创建实体标记,只需调用new EntityTag(string)
。但是你想在上面的代码中实现什么呢?实体标记应该附加到头上,而不是附加到主体上。