Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-enterprise-base
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
base_platform_enterprise
gic-enterprise-base
Commits
789dcec2
Commit
789dcec2
authored
Aug 15, 2019
by
guojuxing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
controller统一返回结果工具类
parent
b97a7ea1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
0 deletions
+85
-0
ResultControllerUtils.java
.../java/com/gic/enterprise/utils/ResultControllerUtils.java
+85
-0
No files found.
gic-enterprise-base-api/src/main/java/com/gic/enterprise/utils/ResultControllerUtils.java
0 → 100644
View file @
789dcec2
package
com
.
gic
.
enterprise
.
utils
;
import
com.gic.api.base.commons.Page
;
import
com.gic.api.base.commons.ServiceResponse
;
import
com.gic.commons.util.EntityUtil
;
import
com.gic.commons.webapi.reponse.RestResponse
;
import
com.gic.enterprise.exception.CommonException
;
import
java.util.List
;
/**
* controller统一返回结果
* @ClassName: ResultControllerUtils
* @Description:
* @author guojuxing
* @date 2019/8/15 2:34 PM
*/
public
class
ResultControllerUtils
{
/**
* 统一返回成功结果
* @Title: commonResult
* @Description:
* @author guojuxing
* @param response
* @return java.lang.Object
*/
public
static
RestResponse
commonResult
(
ServiceResponse
response
)
{
if
(
response
.
isSuccess
())
{
return
RestResponse
.
success
(
response
.
getResult
());
}
else
{
throw
new
CommonException
(
response
);
}
}
/**
* 返回正确结果
* @Title: commonResultObject
* @Description:
* @author guojuxing
* @param response
* @return java.lang.Object
*/
public
static
Object
commonResultObject
(
ServiceResponse
response
)
{
if
(
response
.
isSuccess
())
{
return
response
.
getResult
();
}
else
{
throw
new
CommonException
(
response
);
}
}
/**
* 统一返回成功结果(分页DTO转为VO)
* @Title: commonResultOfListVO
* @Description:
* @author guojuxing
* @param response
* @param clazz
* @return com.gic.commons.webapi.reponse.RestResponse
*/
public
static
RestResponse
commonPageResult
(
ServiceResponse
response
,
Class
<?>
clazz
)
{
if
(
response
.
isSuccess
())
{
Page
page
=
(
Page
)
response
.
getResult
();
page
.
setResult
(
EntityUtil
.
changeEntityListNew
(
clazz
,
page
.
getResult
()));
return
RestResponse
.
success
(
page
);
}
else
{
throw
new
CommonException
(
response
);
}
}
/**
* 统一返回成功结果(DTO转为VO)
* @Title: commonResultOfListVO
* @Description:
* @author guojuxing
* @param response
* @param clazz
* @return com.gic.commons.webapi.reponse.RestResponse
*/
public
static
RestResponse
commonResult
(
ServiceResponse
response
,
Class
<?>
clazz
)
{
if
(
response
.
isSuccess
())
{
return
RestResponse
.
success
(
EntityUtil
.
changeEntityListNew
(
clazz
,
(
List
<?>)
response
.
getResult
()));
}
else
{
throw
new
CommonException
(
response
);
}
}
}
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