Jersey学习记录(三幸运28平台搭建)--过滤拦截器与异常处理

一.全局异常处理器
webservice定义幸运28平台搭建【征途源码论坛zhengtuwl.com】联系方式:QQ:2747044651全局返回错误码是很重要的一个功能,jersey正好就能实现这一功能.

整个流程就是当jersey托管的类发现了异常,抛出给jersey的异常处理器,该异常处理器直接返回自定义的错误代码.

1.定义异常代码
可以使用枚举类,也可以写到配置文件中,再写个工具类获取.看项目需求了.

public enum ErrorCode {
OK(0,"OK"),ID_INVALID(1,"ID is invalid"),OTHER_ERR(2,"未知错误");

private int code;
private String message;

ErrorCode(int code, String message) {
    this.code = code;
    this.message = message;
}

public int getCode() {
    return code;
}

public void setCode(int code) {
    this.code = code;
}

public String getMessage() {幸运28平台搭建

猜你喜欢

转载自blog.51cto.com/13948276/2167641
今日推荐