所以我正在构建一个Web应用程序,我们正在使用JPA和Jersey来使用/生成JSON数据.
我有一个自定义的"EntityException"以及一个自定义的"EntityExceptionMapper"
这是映射器:
@Provider
public class EntityExceptionMapper implements ExceptionMapper<EntityException> {
public EntityExceptionMapper() {
System.out.println("Mapper created");
}
@Override
public Response toResponse(EntityException e) {
System.out.println("This doesnt print!");
return Response.serverError().build();
}
}
Run Code Online (Sandbox Code Playgroud)
我的例外:
public class EntityException extends Exception implements Serializable{
public EntityException(String message) {
super(message);
System.out.println("This prints...");
}
}
Run Code Online (Sandbox Code Playgroud)
我从REST调用中调用它:
@POST
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public String test() throws EntityException{
throw new EntityException("This needs to be send as response!!");
//return "test";
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,当抛出上述异常时,我进入构造函数(打印:"这打印......")编辑:我也得到:"Mapper created!"
但我的回答是空的,我没有从我的toResponse方法到sys.这与球衣网站上的例子非常相似:
https://jersey.java.net/nonav/documentation/1.12/jax-rs.html#d4e435
我错过了什么?
因此,我一直使用视图而不是结果查询作为项目中的实体,我知道我并不孤单,所以我的问题是:
使用视图时,您用作和@Id的用途是什么?有时候,这个问题的答案是微不足道的,但是有时候当您没有一个引人注目的独特领域时,你们会做什么?
现在,我在特定视图中包括了我需要的更多字段,因此我可以混合使用多个唯一字段,并且我在每个字段上都使用了@Id注释,到目前为止,它的工作一直很好。
似乎是上下文,我一直在问自己是否有更标准的方法。