提交 981cce06 作者: 方治民

合并分支 'master' 到 'master'

Master

查看合并请求 chemical-kesai/kshg-api!2
......@@ -2,6 +2,8 @@
package com.yiring.app.config;
import cn.dev33.satoken.exception.NotLoginException;
import com.yiring.app.constant.Code;
import com.yiring.app.exception.CodeException;
import com.yiring.common.core.Result;
import com.yiring.common.core.Status;
import javax.servlet.http.HttpServletResponse;
......@@ -76,7 +78,7 @@ public class GlobalExceptionHandler {
* @return 异常信息反馈 {@link Status#UNAUTHORIZED
*/
@ExceptionHandler(value = NotLoginException.class)
public Result<String> notLoginErrorHandler(Exception e) {
public Result<String> notLoginErrorHandler() {
return Result.no(Status.UNAUTHORIZED);
}
......@@ -87,6 +89,15 @@ public class GlobalExceptionHandler {
public void clientAbortExceptionHandler() {}
/**
* 自定义业务异常
*/
@ExceptionHandler(value = CodeException.class)
public Result<String> customCodeExceptionHandler(CodeException e) {
Code code = e.getCode();
return Result.no(Status.BAD_REQUEST, code.value(), code.reason(), null);
}
/**
* 其他异常
*
* @param e 异常信息
......
......@@ -5,7 +5,7 @@ import io.swagger.annotations.ApiModel;
/**
* 业务状态码
* eg: <code>Result.no(Status.BAD_REQUEST, Code.SUCCESS.value(), Code.SUCCESS.reason())</code>
* eg: <code>throw new CodeException(Code.FAIL)</code>
*
* @author Jim
* @version 0.1
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.exception;
import com.yiring.app.constant.Code;
import lombok.*;
import lombok.experimental.FieldDefaults;
/**
* 业务状态异常
*
* @author Jim
* @version 0.1
* 2022/3/28 11:36
*/
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class CodeException extends RuntimeException {
private static final long serialVersionUID = -4226669531686389671L;
/**
* 业务状态
*/
Code code;
}
......@@ -2,6 +2,7 @@
package com.yiring.app.web;
import com.yiring.app.constant.Code;
import com.yiring.app.exception.CodeException;
import com.yiring.common.core.Result;
import com.yiring.common.param.PageParam;
import com.yiring.common.vo.PageVo;
......@@ -17,7 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@Validated
@Api(tags = "Hello World")
@Api(tags = "Hello")
@RequestMapping("/hello/")
@RestController
public class HelloController {
......@@ -34,7 +35,7 @@ public class HelloController {
*/
@GetMapping("fail")
public Result<String> fail() {
return Result.no(Code.FAIL.value(), Code.FAIL.reason());
throw new CodeException(Code.FAIL);
}
@GetMapping("page")
......
server:
port: 8181
servlet:
context-path: /api
context-path: /basic-api
spring:
application:
......
......@@ -72,6 +72,8 @@ public class UserController {
.title(user.getTitle())
.roles(Permissions.toRoleVos(user.getRoles()))
.permissions(Permissions.toTree(Permissions.toPermissions(user.getRoles()), 0L))
// 默认跳转到用户看板
.homePath("/dashboard/workbench")
.build();
return Result.ok(userInfoVo);
}
......
......@@ -139,16 +139,6 @@ public class Result<T extends Serializable> implements Serializable {
* @return Result
* @see Status
*/
public static <T extends Serializable> Result<T> no(Integer code, String details) {
return no(Status.BAD_REQUEST, code, details, null);
}
/**
* 返回失败响应内容
*
* @return Result
* @see Status
*/
public static <T extends Serializable> Result<T> no(Status status, Integer code, String details, Throwable error) {
Result<T> result = (Result<T>) Result
.builder()
......
......@@ -27,7 +27,7 @@ import org.springframework.web.multipart.MultipartFile;
@Slf4j
@Validated
@Api(tags = "Minio S3")
@Api(tags = "Minio")
@RestController
@RequestMapping("/common/minio/")
public class MinioController {
......@@ -40,7 +40,7 @@ public class MinioController {
*/
@ApiOperation(value = "文件上传")
@PostMapping(value = "upload", headers = "Content-Type=Multipart/Form-Data")
public Result<String> minio(@ApiParam(value = "文件", required = true) @RequestPart("file") MultipartFile file) {
public Result<String> upload(@ApiParam(value = "文件", required = true) @RequestPart("file") MultipartFile file) {
try {
Snowflake snowflake = IdUtil.getSnowflake(1, 1);
long uuid = snowflake.nextId();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论