這是我寫的HttpMessageNotReadableException例外處理,
這個"succ_flag" 給的是boolean 型,現在傳了一個數字,如何把下面的 msg 報錯資訊改為 “succ_flag”:請求引數不合法, 也就是 欄位名:請求引數不合法 這種型別的 。 本人是個新手,還請各位大佬多多指點,請各位大佬 幫幫忙,謝謝了。
uj5u.com熱心網友回復:
捕獲這個例外@ExceptionHandler(InvalidFormatException.class)
public R handHttpConverterException(InvalidFormatException e){
String errors = "";
List<JsonMappingException.Reference> path = e.getPath();
for(JsonMappingException.Reference reference : path){
errors += "引數名:"+reference.getFieldName()+" 輸入不合法,需要的是 "+e.getTargetType().getName() + " 型別,"+"提交的值是:"+e.getValue().toString();
log.info("引數名:{}",reference.getFieldName());
}
log.info("提交的引數值:{}",e.getValue().toString());
log.info("需要的引數型別:{}"+e.getTargetType().getName());
return R.error(errors);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/246249.html
標籤:Java相關
上一篇:關注,粉絲功能怎么實作更高效
