有时候我们经常遇到逻辑正常执行时返回客户端指定格式的数据,比如json,但是遇NullPointerException空指针异常,NoSuchMethodException调用的方法不存在异常,返回给客户端的是服务端异常堆栈信息,导致客户端不能正常解析数据;这明显不是我们想要的;或者我们已经用@RestControllerAdvice+ @ExceptionHandler进行统一异常处理,但是每次返回的时候都要写上return new RestRest().success(data)这里需要用到ResponseBodyAdvice在返回客户端之前进行统一处理。
先记录一下统一异常处理:
统一异常处理类
@Slf4j
@RestControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
@ExceptionHandler(value = {ParameterException.class})
public ErrorInfo
自定义异常类
@Getter
public class NoPermissionException extends RuntimeException {
public NoPermissionException() {
}
public NoPermissionException(String message) {
super(message);
}
public NoPermissionException(String message, Throwable cause) {
super(message, cause);
}
public NoPermissionException(Throwable cause) {
super(cause);
}
public NoPermissionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
@Override
public LostVo queryLostVo(String lostId) {
log.info("lostId:{}", lostId);
if (!StringUtils.isNotEmpty(lostId)) {
throw new ParameterException("请检查参数是否正确");
} else {
Lost lost = lostMapper.selectByPrimaryKey(lostId);
User user = userMapper.selectByOpenId(lost.getLostOpenid());
LostVo lostVo = new LostVo();
…………
}
//
GetUrlParam:function GetUrlParam(param){
var reg = new RegExp("(^|&)"+ param +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null
==================================================
1、打开PowerDesigner12,在菜单中按照如下方式进行操作
file->Reverse Engineer->DataBase
点击后,弹出 New Physical Data Model 的对话框
2、在General选项卡中
Model name:模板名字,自
网站配置是apache+tomcat,tomcat没有报错,apache报错是:
The proxy server received an invalid response from an upstream server. The proxy server could not handle the request GET /. Reason: Error reading fr
Free variable A free variable of an expression is a variable that’s used inside the expression but not defined inside the expression. For instance, in the function literal expression (x: Int) => (x
Part Ⅰ:
《阿甘正传》Forrest Gump经典中英文对白
Forrest: Hello! My names Forrest. Forrest Gump. You wanna Chocolate? I could eat about a million and a half othese. My momma always said life was like a box ochocol
Json在数据传输中很好用,原因是JSON 比 XML 更小、更快,更易解析。
在Java程序中,如何使用处理JSON,现在有很多工具可以处理,比较流行常用的是google的gson和alibaba的fastjson,具体使用如下:
1、读取json然后处理
class ReadJSON
{
public static void main(String[] args)