2

在我的 Jersey Rest Service 中,我尝试创建一个实体标签:

String content = 12sdfs-345dsdfsdf-231yscysd;
String createdContent = create(content);
return Response.created(createdUri).entity(createdContent).build();

就像它写在球衣文档中一样。但是createdContentnull。怎么了?

完整的代码是:

@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 章

4

1 回答 1

3

要创建实体标签,只需调用new EntityTag(string). 但是你想在上面的代码中实现什么?实体标签应附加到标题,而不是正文。

于 2012-06-21T15:50:31.827 回答