我正在尝试使用dropwizard创建一个RESTful API,但是,当我尝试键入资源/ ID时,它向我返回错误500,但是当我尝试返回在ArrayList中创建的所有对象时,一切正常
@Path("/avioes")
@Produces(MediaType.APPLICATION_JSON)
public class AvioesResource {
private AvioesDAO dao;
public AvioesResource(AvioesDAO dao) {
this.dao = dao;
}
@POST
public Aviao create(Aviao aviao) {
return dao.criar(aviao);
}
@GET
public List<Aviao> read() {
return dao.lerTodos();
}
@PUT
@Path("{banana}")
public Response update(@PathParam("banana") LongParam id, Aviao aviao) {
if(dao.atualizar(id.get(), aviao)) {
return Response.ok().build();
}
throw new WebApplicationException("Não rolou alterar", Response.Status.NOT_FOUND);
}
@DELETE
@Path("{maca}")
public Response delete(@PathParam("maca") LongParam id, Aviao aviao) {
if(dao.apagar(id.get())) {
return Response.ok().build();
}
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
答案 0 :(得分:1)
您没有映射API方法来获取单个资源。您需要这样的东西:
@GET
@Path("{id}")
public Aviao read(@PathParam("id") LongParam id) {
return dao.get(id);
}