Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
PaperExamStudent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
霍传世
PaperExamStudent
Commits
96438200
Commit
96438200
authored
Apr 15, 2025
by
霍传世
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改全局异常捕获按钮
parent
1f319db3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
1 deletion
+30
-1
src/main/java/com/yuda/paperstudentconfig/config/WebConfigurer.java
...ava/com/yuda/paperstudentconfig/config/WebConfigurer.java
+1
-1
src/main/java/com/yuda/paperstudentconfig/controller/LoginController.java
...m/yuda/paperstudentconfig/controller/LoginController.java
+13
-0
src/main/java/com/yuda/paperstudentconfig/exception/GlobalExceptionHandler.java
.../paperstudentconfig/exception/GlobalExceptionHandler.java
+16
-0
No files found.
src/main/java/com/yuda/paperstudentconfig/config/WebConfigurer.java
View file @
96438200
...
...
@@ -18,7 +18,7 @@ public class WebConfigurer implements WebMvcConfigurer {
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
// 拦截所有请求,通过判断是否有 @LoginRequired 注解 决定是否需要登录
registry
.
addInterceptor
(
loginInterceptor
).
addPathPatterns
(
"/**"
).
excludePathPatterns
(
"/login/signIn"
)
registry
.
addInterceptor
(
loginInterceptor
).
addPathPatterns
(
"/**"
).
excludePathPatterns
(
"/login/signIn"
,
"/login/testException"
)
.
excludePathPatterns
(
// 允许对于网站静态资源的无授权访问
"/"
,
"/*.html"
,
...
...
src/main/java/com/yuda/paperstudentconfig/controller/LoginController.java
View file @
96438200
...
...
@@ -54,6 +54,19 @@ public class LoginController {
}
}
// ... existing code ...
@GetMapping
(
"/testException"
)
public
ResponseResult
testException
(
@RequestParam
Integer
num
)
{
if
(
num
==
0
)
{
throw
new
RuntimeException
(
"除数不能为零"
);
}
int
result
=
100
/
num
;
return
ResponseResult
.
success
(
"计算结果"
,
result
);
}
// ... existing code ...
@PostMapping
(
"/signOut"
)
public
ResponseResult
logout
(
@RequestBody
AccountVo
accountVo
)
{
// 从Redis中删除token
...
...
src/main/java/com/yuda/paperstudentconfig/exception/GlobalExceptionHandler.java
0 → 100644
View file @
96438200
package
com.yuda.paperstudentconfig.exception
;
import
com.yuda.paperstudentconfig.utils.ResponseResult
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
@RestControllerAdvice
public
class
GlobalExceptionHandler
{
@ExceptionHandler
(
Exception
.
class
)
public
ResponseResult
handleException
(
Exception
e
)
{
// 返回友好的错误信息
return
ResponseResult
.
fail
(
500
,
"系统异常,请联系相关客服人员"
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment