feat(init): 配置文件
This commit is contained in:
parent
2a11794631
commit
0d1f2260f9
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="GitCommitMessageStorage">
|
||||||
|
<option name="messageStorage">
|
||||||
|
<MessageStorage />
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -1,4 +1,4 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
|
@ -17,7 +17,28 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<!--添加依赖-->
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>joda-time</groupId>
|
||||||
|
<artifactId>joda-time</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.atguigu</groupId>
|
||||||
|
<artifactId>model</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
package com.atguigu;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hello world!
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class App
|
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
|
||||||
{
|
|
||||||
System.out.println( "Hello World!" );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.atguigu.ssyx.common.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MybatisPlus配置类
|
||||||
|
*/
|
||||||
|
@EnableTransactionManagement
|
||||||
|
@Configuration
|
||||||
|
@MapperScan("com.atguigu.ssyx.*.mapper")
|
||||||
|
public class MybatisPlusConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mp插件
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor optimisticLockerInnerInterceptor() {
|
||||||
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
// 向Mybatis过滤器链中添加分页拦截器
|
||||||
|
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||||
|
// 乐观锁插件
|
||||||
|
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
|
||||||
|
// 防止全表删除
|
||||||
|
interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
package com.atguigu.ssyx.common.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
|
import springfox.documentation.builders.ParameterBuilder;
|
||||||
|
import springfox.documentation.builders.PathSelectors;
|
||||||
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
|
import springfox.documentation.schema.ModelRef;
|
||||||
|
import springfox.documentation.service.ApiInfo;
|
||||||
|
import springfox.documentation.service.Contact;
|
||||||
|
import springfox.documentation.service.Parameter;
|
||||||
|
import springfox.documentation.spi.DocumentationType;
|
||||||
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
|
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swagger2配置信息
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@EnableSwagger2WebMvc
|
||||||
|
public class Swagger2Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Docket webApiConfig() {
|
||||||
|
List<Parameter> pars = new ArrayList<>();
|
||||||
|
ParameterBuilder tokenPar = new ParameterBuilder();
|
||||||
|
tokenPar.name("userId")
|
||||||
|
.description("用户token")
|
||||||
|
//.defaultValue(JwtHelper.createToken(1L, "admin"))
|
||||||
|
.defaultValue("1")
|
||||||
|
.modelRef(new ModelRef("string"))
|
||||||
|
.parameterType("header")
|
||||||
|
.required(false)
|
||||||
|
.build();
|
||||||
|
pars.add(tokenPar.build());
|
||||||
|
|
||||||
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.groupName("webApi")
|
||||||
|
.apiInfo(webApiInfo())
|
||||||
|
.select()
|
||||||
|
// 只显示api路径下的页面
|
||||||
|
.apis(RequestHandlerSelectors.basePackage("com.atguigu.ssyx"))
|
||||||
|
.paths(PathSelectors.regex("/api/.*"))
|
||||||
|
.build()
|
||||||
|
.globalOperationParameters(pars);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Docket adminApiConfig() {
|
||||||
|
List<Parameter> pars = new ArrayList<>();
|
||||||
|
ParameterBuilder tokenPar = new ParameterBuilder();
|
||||||
|
tokenPar.name("adminId")
|
||||||
|
.description("用户token")
|
||||||
|
.defaultValue("1")
|
||||||
|
.modelRef(new ModelRef("string"))
|
||||||
|
.parameterType("header")
|
||||||
|
.required(false)
|
||||||
|
.build();
|
||||||
|
pars.add(tokenPar.build());
|
||||||
|
|
||||||
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.groupName("adminApi")
|
||||||
|
.apiInfo(adminApiInfo())
|
||||||
|
.select()
|
||||||
|
// 只显示admin路径下的页面
|
||||||
|
.apis(RequestHandlerSelectors.basePackage("com.atguigu.ssyx"))
|
||||||
|
.paths(PathSelectors.regex("/admin/.*"))
|
||||||
|
.build()
|
||||||
|
.globalOperationParameters(pars);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApiInfo webApiInfo() {
|
||||||
|
return new ApiInfoBuilder()
|
||||||
|
.title("网站-API文档")
|
||||||
|
.description("本文档描述了尚上优选网站微服务接口定义")
|
||||||
|
.version("1.0")
|
||||||
|
.contact(new Contact("atguigu", "http://atguigu.com", "atguigu"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApiInfo adminApiInfo() {
|
||||||
|
return new ApiInfoBuilder()
|
||||||
|
.title("后台管理系统-API文档")
|
||||||
|
.description("本文档描述了尚上优选后台系统服务接口定义")
|
||||||
|
.version("1.0")
|
||||||
|
.contact(new Contact("atguigu", "http://atguigu.com", "atguigu"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.atguigu.ssyx.common.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 信息提示常量类
|
||||||
|
*/
|
||||||
|
public class MessageConstant {
|
||||||
|
public static final String PASSWORD_ERROR = "密码错误";
|
||||||
|
public static final String OLD_PASSWORD_ERROR = "旧密码不匹配";
|
||||||
|
public static final String OLD_PASSWORD_SAME_NEW_PASSWORD = "旧密码与新密码相同";
|
||||||
|
public static final String ACCOUNT_NOT_FOUND = "账号不存在";
|
||||||
|
public static final String ACCOUNT_LOCKED = "账号被锁定";
|
||||||
|
public static final String UNKNOWN_ERROR = "未知错误";
|
||||||
|
public static final String USER_NOT_LOGIN = "用户未登录";
|
||||||
|
public static final String USER_TOKEN_OUT_OF_DATE = "用户登录过期";
|
||||||
|
public static final String LOGIN_FAILED = "登录失败";
|
||||||
|
public static final String UPLOAD_FAILED = "文件上传失败";
|
||||||
|
public static final String PASSWORD_EDIT_FAILED = "密码修改失败";
|
||||||
|
public static final String ALREADY_EXISTS = "已存在";
|
||||||
|
public static final String REQUEST_NOT_EMPTY = "请求不为空";
|
||||||
|
public static final String UPDATE_ID_IS_NOT_EMPTY = "删除id不能为空";
|
||||||
|
public static final String DELETE_ID_IS_NOT_EMPTY = "修改id不能为空";
|
||||||
|
public static final String MENU_IS_NOT_EXIST = "菜单不存在";
|
||||||
|
public static final String SAVE_DTO_IS_NULL = "添加参数不能为空";
|
||||||
|
public static final String UPDATE_DTO_IS_NULL = "修改参数不能为空";
|
||||||
|
public static final String FIND_ID_IS_NOT_EMPTY = "查询ID不能为空";
|
||||||
|
public static final String MESSAGE_CODE_NOT_PASS = "短信验证码未过期";
|
||||||
|
public static final String MESSAGE_CODE_UNAUTHORIZED = "短信验证码未授权,请联系管理员";
|
||||||
|
public static final String VERIFICATION_CODE_ERROR = "验证码错误";
|
||||||
|
public static final String USER_DOES_NOT_EXIST = "用户不存在";
|
||||||
|
public static final String USER_DOES_IS_EXIST = "用户已存在";
|
||||||
|
public static final String VERIFICATION_CODE_IS_EMPTY = "请先发送验证码";
|
||||||
|
public static final String LOGIN_DTO_IS_EMPTY = "登录参数不能为空";
|
||||||
|
public static final String TOKEN_IS_EMPTY = "token为空";
|
||||||
|
public static final String DATA_IS_EMPTY = "数据为空";
|
||||||
|
public static final String STOCK_LESS = "库存不足";
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.atguigu.ssyx.common.context;
|
||||||
|
|
||||||
|
|
||||||
|
public class BaseContext {
|
||||||
|
public static ThreadLocal<Long> threadLocal = new ThreadLocal<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前用户id
|
||||||
|
*/
|
||||||
|
public static Long getUserId() {
|
||||||
|
return threadLocal.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置用户id
|
||||||
|
*/
|
||||||
|
public static void setUserId(Long userId) {
|
||||||
|
threadLocal.set(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移出当前id
|
||||||
|
*/
|
||||||
|
public static void remove() {
|
||||||
|
threadLocal.remove();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.atguigu.ssyx.common.exception;
|
||||||
|
|
||||||
|
import com.atguigu.ssyx.common.result.ResultCodeEnum;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@Slf4j
|
||||||
|
public class BunnyException extends RuntimeException {
|
||||||
|
Integer code;// 状态码
|
||||||
|
String message;// 描述信息
|
||||||
|
|
||||||
|
public BunnyException(Integer code, String message) {
|
||||||
|
super(message);
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BunnyException(String message) {
|
||||||
|
super(message);
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BunnyException(ResultCodeEnum codeEnum) {
|
||||||
|
super(codeEnum.getMessage());
|
||||||
|
this.code = codeEnum.getCode();
|
||||||
|
this.message = codeEnum.getMessage();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.atguigu.ssyx.common.exception;
|
||||||
|
|
||||||
|
|
||||||
|
import com.atguigu.ssyx.common.constant.MessageConstant;
|
||||||
|
import com.atguigu.ssyx.common.result.Result;
|
||||||
|
import com.atguigu.ssyx.common.result.ResultCodeEnum;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
import java.nio.file.AccessDeniedException;
|
||||||
|
import java.sql.SQLIntegrityConstraintViolationException;
|
||||||
|
|
||||||
|
@RestControllerAdvice
|
||||||
|
@Slf4j
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
// 自定义异常信息
|
||||||
|
@ExceptionHandler(BunnyException.class)
|
||||||
|
@ResponseBody
|
||||||
|
public Result<Object> exceptionHandler(BunnyException exception) {
|
||||||
|
log.error("GlobalExceptionHandler===>自定义异常信息:{}", exception.getMessage());
|
||||||
|
|
||||||
|
Integer code = exception.getCode() != null ? exception.getCode() : 500;
|
||||||
|
return Result.error(null, code, exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 运行时异常信息
|
||||||
|
@ExceptionHandler(RuntimeException.class)
|
||||||
|
@ResponseBody
|
||||||
|
public Result<Object> exceptionHandler(RuntimeException exception) {
|
||||||
|
log.error("GlobalExceptionHandler===>运行时异常信息:{}", exception.getMessage());
|
||||||
|
|
||||||
|
return Result.error(null, 500, "出错了啦");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 捕获系统异常
|
||||||
|
@ExceptionHandler(Exception.class)
|
||||||
|
@ResponseBody
|
||||||
|
public Result<Object> error(Exception exception) {
|
||||||
|
log.error("GlobalExceptionHandler===>系统异常信息:{}", exception.getMessage());
|
||||||
|
|
||||||
|
return Result.error(null, 500, exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 特定异常处理
|
||||||
|
@ExceptionHandler(ArithmeticException.class)
|
||||||
|
@ResponseBody
|
||||||
|
public Result<Object> error(ArithmeticException exception) {
|
||||||
|
log.error("GlobalExceptionHandler===>特定异常信息:{}", exception.getMessage());
|
||||||
|
|
||||||
|
return Result.error(null, 500, exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// spring security异常
|
||||||
|
@ExceptionHandler(AccessDeniedException.class)
|
||||||
|
@ResponseBody
|
||||||
|
public Result<String> error(AccessDeniedException exception) throws AccessDeniedException {
|
||||||
|
log.error("GlobalExceptionHandler===>spring security异常:{}", exception.getMessage());
|
||||||
|
|
||||||
|
return Result.error(ResultCodeEnum.PERMISSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理SQL异常
|
||||||
|
@ExceptionHandler(SQLIntegrityConstraintViolationException.class)
|
||||||
|
@ResponseBody
|
||||||
|
public Result<String> exceptionHandler(SQLIntegrityConstraintViolationException exception) {
|
||||||
|
log.error("GlobalExceptionHandler===>处理SQL异常:{}", exception.getMessage());
|
||||||
|
|
||||||
|
String message = exception.getMessage();
|
||||||
|
if (message.contains("Duplicate entry")) {
|
||||||
|
// 截取用户名
|
||||||
|
String username = message.split(" ")[2];
|
||||||
|
// 错误信息
|
||||||
|
String errorMessage = username + MessageConstant.ALREADY_EXISTS;
|
||||||
|
return Result.error(errorMessage);
|
||||||
|
} else {
|
||||||
|
return Result.error(MessageConstant.UNKNOWN_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,174 @@
|
||||||
|
package com.atguigu.ssyx.common.result;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class Result<T> {
|
||||||
|
// 状态码
|
||||||
|
private Integer code;
|
||||||
|
// 返回消息
|
||||||
|
private String message;
|
||||||
|
// 返回数据
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 自定义返回体
|
||||||
|
*
|
||||||
|
* @param data 返回体
|
||||||
|
* @return Result<T>
|
||||||
|
*/
|
||||||
|
protected static <T> Result<T> build(T data) {
|
||||||
|
Result<T> result = new Result<>();
|
||||||
|
if (data != null) {
|
||||||
|
result.setData(data);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 自定义返回体,使用ResultCodeEnum构建
|
||||||
|
*
|
||||||
|
* @param body 返回体
|
||||||
|
* @param codeEnum 返回状态码
|
||||||
|
* @return Result<T>
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> build(T body, ResultCodeEnum codeEnum) {
|
||||||
|
Result<T> result = build(body);
|
||||||
|
result.setCode(codeEnum.getCode());
|
||||||
|
result.setMessage(codeEnum.getMessage());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 自定义返回体
|
||||||
|
*
|
||||||
|
* @param body 返回体
|
||||||
|
* @param code 返回状态码
|
||||||
|
* @param message 返回消息
|
||||||
|
* @return Result<T>
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> build(T body, Integer code, String message) {
|
||||||
|
Result<T> result = build(body);
|
||||||
|
result.setCode(code);
|
||||||
|
result.setMessage(message);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 操作成功
|
||||||
|
*
|
||||||
|
* @return Result<T>
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> success() {
|
||||||
|
return Result.success(null, ResultCodeEnum.SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 操作成功
|
||||||
|
*
|
||||||
|
* @param data baseCategory1List
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> success(T data) {
|
||||||
|
return build(data, ResultCodeEnum.SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 操作成功-状态码
|
||||||
|
*
|
||||||
|
* @param codeEnum 状态码
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> success(ResultCodeEnum codeEnum) {
|
||||||
|
return success(null, codeEnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 操作成功-自定义返回数据和状态码
|
||||||
|
*
|
||||||
|
* @param data 返回体
|
||||||
|
* @param codeEnum 状态码
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> success(T data, ResultCodeEnum codeEnum) {
|
||||||
|
return build(data, codeEnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 操作失败-自定义返回数据和状态码
|
||||||
|
*
|
||||||
|
* @param data 返回体
|
||||||
|
* @param message 错误信息
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> success(T data, String message) {
|
||||||
|
return build(data, 200, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 操作失败-自定义返回数据和状态码
|
||||||
|
*
|
||||||
|
* @param data 返回体
|
||||||
|
* @param code 状态码
|
||||||
|
* @param message 错误信息
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> success(T data, Integer code, String message) {
|
||||||
|
return build(data, code, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 操作失败
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> error() {
|
||||||
|
return Result.build(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 操作失败-自定义返回数据
|
||||||
|
*
|
||||||
|
* @param data 返回体
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> error(T data) {
|
||||||
|
return build(data, ResultCodeEnum.FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 操作失败-状态码
|
||||||
|
*
|
||||||
|
* @param codeEnum 状态码
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> error(ResultCodeEnum codeEnum) {
|
||||||
|
return build(null, codeEnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 操作失败-自定义返回数据和状态码
|
||||||
|
*
|
||||||
|
* @param data 返回体
|
||||||
|
* @param codeEnum 状态码
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> error(T data, ResultCodeEnum codeEnum) {
|
||||||
|
return build(data, codeEnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 操作失败-自定义返回数据和状态码
|
||||||
|
*
|
||||||
|
* @param data 返回体
|
||||||
|
* @param code 状态码
|
||||||
|
* @param message 错误信息
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> error(T data, Integer code, String message) {
|
||||||
|
return build(data, code, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 操作失败-自定义返回数据和状态码
|
||||||
|
*
|
||||||
|
* @param data 返回体
|
||||||
|
* @param message 错误信息
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> error(T data, String message) {
|
||||||
|
return build(null, 500, message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.atguigu.ssyx.common.result;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一返回结果状态信息类
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum ResultCodeEnum {
|
||||||
|
|
||||||
|
SUCCESS(200, "成功"),
|
||||||
|
FAIL(201, "失败"),
|
||||||
|
SERVICE_ERROR(2012, "服务异常"),
|
||||||
|
DATA_ERROR(204, "数据异常"),
|
||||||
|
ILLEGAL_REQUEST(205, "非法请求"),
|
||||||
|
REPEAT_SUBMIT(206, "重复提交"),
|
||||||
|
|
||||||
|
LOGIN_AUTH(208, "未登陆"),
|
||||||
|
PERMISSION(209, "没有权限"),
|
||||||
|
|
||||||
|
ORDER_PRICE_ERROR(210, "订单商品价格变化"),
|
||||||
|
ORDER_STOCK_FALL(204, "订单库存锁定失败"),
|
||||||
|
CREATE_ORDER_FAIL(210, "创建订单失败"),
|
||||||
|
|
||||||
|
COUPON_GET(220, "优惠券已经领取"),
|
||||||
|
COUPON_LIMIT_GET(221, "优惠券已发放完毕"),
|
||||||
|
|
||||||
|
URL_ENCODE_ERROR(216, "URL编码失败"),
|
||||||
|
ILLEGAL_CALLBACK_REQUEST_ERROR(217, "非法回调请求"),
|
||||||
|
FETCH_ACCESSTOKEN_FAILD(218, "获取accessToken失败"),
|
||||||
|
FETCH_USERINFO_ERROR(219, "获取用户信息失败"),
|
||||||
|
|
||||||
|
|
||||||
|
SKU_LIMIT_ERROR(230, "购买个数不能大于限购个数"),
|
||||||
|
REGION_OPEN(240, "该区域已开通"),
|
||||||
|
REGION_NO_OPEN(240, "该区域未开通"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final Integer code;
|
||||||
|
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
ResultCodeEnum(Integer code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,27 +17,42 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<!--添加依赖-->
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>httpclient</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--mybatis-plus-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.jsonwebtoken</groupId>
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
<artifactId>jjwt</artifactId>
|
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||||
|
<!--在引用时请在maven中央仓库搜索2.X最新版本号-->
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>joda-time</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>joda-time</artifactId>
|
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.atguigu</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>model</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--创建索引库的-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
package com.atguigu;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hello world!
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class App
|
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
|
||||||
{
|
|
||||||
System.out.println( "Hello World!" );
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue