gpt4 book ai didi

java - 创建实体标签,但它是空的

转载 作者:可可西里 更新时间:2023-11-01 16:30:54 26 4
gpt4 key购买 nike

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

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

就像 Jersey 文档中写的一样。但是 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 章

最佳答案

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

关于java - 创建实体标签,但它是空的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11125584/

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