Compare commits

...

16 Commits

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,7 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<ScalaCodeStyleSettings>
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
</ScalaCodeStyleSettings>
</code_scheme>
</component>

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/superMarket-backend/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21.0.2" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/远程测试仓库1.iml" filepath="$PROJECT_DIR$/.idea/远程测试仓库1.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,32 @@
3
3
3
3
33
3
3
3
33
3
3
3
3
3
34
34
333
33
3
3
33
3
3
342
5
66
7878
3

@ -1,33 +1,53 @@
// 包声明:定义当前类所在的包路径
package com.shanzhu.market.common.advice;
// 定义当前类所在的包路径
// 导入依赖的类库
import com.shanzhu.market.common.constants.HttpStatus; // HTTP状态码常量
import com.shanzhu.market.common.exception.BusinessException; // 自定义业务异常
import com.shanzhu.market.common.web.response.JsonResult; // 统一响应格式工具类
import org.springframework.web.bind.annotation.ExceptionHandler; // Spring异常处理注解
import org.springframework.web.bind.annotation.RestControllerAdvice; // Spring控制器增强注解
import com.shanzhu.market.common.constants.HttpStatus;
// 导入包含HTTP状态码常量的工具类
import com.shanzhu.market.common.exception.BusinessException;
// 导入自定义的业务异常类
import com.shanzhu.market.common.web.response.JsonResult;
// 导入用于封装JSON响应结果的工具类
import org.springframework.web.bind.annotation.ExceptionHandler;
// 导入Spring框架的异常处理注解
import org.springframework.web.bind.annotation.RestControllerAdvice;
// 导入Spring框架的全局异常处理注解
/**
*
*
*/
@RestControllerAdvice // 标识该类为全局REST控制器异常处理器
@RestControllerAdvice
// 声明该类为全局异常处理类返回JSON格式的响应
public class ExceptionControllerAdvice {
// 处理所有RuntimeException及其子类异常
@ExceptionHandler(RuntimeException.class)
// 声明方法处理RuntimeException类型的异常
public JsonResult<?> commonExceptionHandler(RuntimeException ex){
ex.printStackTrace(); // 打印异常堆栈跟踪(生产环境建议替换为日志记录)
return JsonResult.error( // 返回标准错误响应
HttpStatus.CODE_BUSINESS_ERROR, // 使用预定义的业务错误码
ex.getMessage()); // 携带异常消息
// 定义处理RuntimeException异常的方法返回JsonResult对象
ex.printStackTrace();
// 打印异常堆栈信息到控制台
return JsonResult.error(HttpStatus.CODE_BUSINESS_ERROR,ex.getMessage());
// 返回封装的错误响应,包含状态码和异常信息
}
// 专门处理自定义业务异常
@ExceptionHandler(BusinessException.class)
// 声明方法处理BusinessException类型的异常
public JsonResult<?> businessHanler(BusinessException ex){
return JsonResult.error( // 返回标准错误响应
HttpStatus.CODE_BUSINESS_ERROR, // 使用相同的业务错误码保持一致性
ex.getMessage()); // 携带业务异常消息
// 定义处理BusinessException异常的方法返回JsonResult对象
return JsonResult.error(HttpStatus.CODE_BUSINESS_ERROR,ex.getMessage());
// 返回封装的错误响应,包含状态码和异常信息
}
}
}

@ -1,20 +0,0 @@
package com.shanzhu.market.common.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MpConfig {
/*mybatis plus分页插件生效*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
paginationInnerInterceptor.setOverflow(true); //合理化
interceptor.addInnerInterceptor(paginationInnerInterceptor);
return interceptor;
}
}
Loading…
Cancel
Save