鍍金池/ 問答/Java  Linux  網(wǎng)絡(luò)安全/ Spring全局異常處理器返回一個(gè) responseBean 調(diào)用了不該調(diào)用的

Spring全局異常處理器返回一個(gè) responseBean 調(diào)用了不該調(diào)用的構(gòu)造器

@ControllerAdvice
public class DefaultExceptionHandler {
/**
 * 沒有權(quán)限 異常
 */
@ExceptionHandler({UnauthorizedException.class})
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public ResponseBean processUnauthenticatedException(NativeWebRequest request, UnauthorizedException e) {
    return new ResponseBean(ResponseBean.FAIL,"您沒有權(quán)限");
}

}

代碼如上 下面是我的ResponseBean的構(gòu)造方法

public ResponseBean() {
        super();
    }

    public ResponseBean(String code, String msg) {//講道理應(yīng)該調(diào)用此構(gòu)造方法
        super();
        this.code = code;
        this.msg = msg;
    }

    public ResponseBean(String code, String msg, List<?> data) {
        super();
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    
    public ResponseBean(String code,String msg,List<?> data,int count){//不講道理的調(diào)用了此方法
        super();
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.count=count;
    }

當(dāng)前返回的json格式如下

{"code":"1","count":0,"msg":"您沒有權(quán)限"}
回答
編輯回答
汐顏

沒有吧,應(yīng)該是 count 有 setter/getter 方法,并且 count 的int 默認(rèn)值是 0

2017年4月14日 07:57