mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-13 04:01:40 +08:00
前端书籍搜索页面、手机详情页面;前端优化;后端异常处理;添加项目Gitee和GitHub仓库地址;搜索按钮样式美化
This commit is contained in:
@@ -2,9 +2,18 @@ package plus.bookshelf.Controller.Controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
// import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import plus.bookshelf.Common.Error.BusinessErrorCode;
|
||||
import plus.bookshelf.Common.Error.BusinessException;
|
||||
import plus.bookshelf.Common.Response.CommonReturnType;
|
||||
import plus.bookshelf.Common.Response.CommonReturnTypeStatus;
|
||||
import plus.bookshelf.Service.Model.UserModel;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -41,4 +50,24 @@ public class BaseController {
|
||||
// redisTemplate.opsForValue().set(uuidToken, userModel);
|
||||
return uuidToken;
|
||||
}
|
||||
|
||||
// 定义ExceptionHandler解决未被Controller层吸收的Exception
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public Object handlerException(HttpServletRequest request, Exception ex) {
|
||||
|
||||
HashMap<Object, Object> responseData = new HashMap<>();
|
||||
|
||||
if (ex instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) ex;
|
||||
responseData.put("errCode", businessException.getErrCode());
|
||||
responseData.put("errMsg", businessException.getErrMsg());
|
||||
} else {
|
||||
responseData.put("errCode", BusinessErrorCode.UNKNOWN_ERROR.getErrCode());
|
||||
responseData.put("errMsg", BusinessErrorCode.UNKNOWN_ERROR.getErrMsg());
|
||||
}
|
||||
|
||||
return CommonReturnType.create(responseData, CommonReturnTypeStatus.FAILED);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user