Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
279d45e8
Commit
279d45e8
authored
Aug 24, 2017
by
stylefeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
配置异常拦截
parent
0f372822
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
2 deletions
+50
-2
guns-core/src/main/java/com/stylefeng/guns/core/aop/BaseControllerExceptionHandler.java
+49
-0
guns-core/src/main/java/com/stylefeng/guns/core/config/FastjsonConfig.java
+1
-2
No files found.
guns-core/src/main/java/com/stylefeng/guns/core/aop/BaseControllerExceptionHandler.java
0 → 100644
View file @
279d45e8
package
com
.
stylefeng
.
guns
.
core
.
aop
;
import
com.stylefeng.guns.core.base.tips.ErrorTip
;
import
com.stylefeng.guns.core.exception.GunsException
;
import
com.stylefeng.guns.core.exception.GunsExceptionEnum
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
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
;
/**
* 全局的的异常拦截器(拦截所有的控制器)(带有@RequestMapping注解的方法上都会拦截)
*
* @author fengshuonan
* @date 2016年11月12日 下午3:19:56
*/
public
class
BaseControllerExceptionHandler
{
private
Logger
log
=
LoggerFactory
.
getLogger
(
this
.
getClass
());
/**
* 拦截业务异常
*
* @author fengshuonan
*/
@ExceptionHandler
(
GunsException
.
class
)
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ResponseBody
public
ErrorTip
notFount
(
GunsException
e
)
{
log
.
error
(
"业务异常:"
,
e
);
return
new
ErrorTip
(
e
.
getCode
(),
e
.
getMessage
());
}
/**
* 拦截未知的运行时异常
*
* @author fengshuonan
*/
@ExceptionHandler
(
RuntimeException
.
class
)
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ResponseBody
public
ErrorTip
notFount
(
RuntimeException
e
)
{
log
.
error
(
"运行时异常:"
,
e
);
return
new
ErrorTip
(
GunsExceptionEnum
.
SERVER_ERROR
.
getCode
(),
GunsExceptionEnum
.
SERVER_ERROR
.
getMessage
());
}
}
guns-core/src/main/java/com/stylefeng/guns/core/config/FastjsonConfig.java
View file @
279d45e8
...
...
@@ -32,8 +32,7 @@ public class FastjsonConfig {
FastJsonConfig
fastJsonConfig
=
new
FastJsonConfig
();
fastJsonConfig
.
setSerializerFeatures
(
SerializerFeature
.
PrettyFormat
,
SerializerFeature
.
WriteMapNullValue
,
SerializerFeature
.
WriteClassName
SerializerFeature
.
WriteMapNullValue
);
fastJsonConfig
.
setDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
ValueFilter
valueFilter
=
new
ValueFilter
()
{
...
...
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