Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
slm-bi
Project
Project
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
林锐标
slm-bi
Commits
a1ed68f6
Commit
a1ed68f6
authored
Apr 23, 2021
by
梁光意
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
把session修改为request
parent
83ad1535
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
5 deletions
+16
-5
SysMetaObjectHandler.java
...n/java/com/syc/slm/slmbi/config/SysMetaObjectHandler.java
+1
-3
BaseRestController.java
...java/com/syc/slm/slmbi/controller/BaseRestController.java
+2
-2
SysExceptionHandler.java
...n/java/com/syc/slm/slmbi/handler/SysExceptionHandler.java
+13
-0
No files found.
src/main/java/com/syc/slm/slmbi/config/SysMetaObjectHandler.java
View file @
a1ed68f6
...
...
@@ -14,8 +14,6 @@ import org.apache.ibatis.reflection.MetaObject;
import
org.springframework.stereotype.Component
;
import
javax.servlet.http.HttpServletRequest
;
import
java.nio.channels.SelectableChannel
;
import
java.time.LocalDateTime
;
import
java.util.Date
;
import
java.util.Map
;
import
java.util.function.Supplier
;
...
...
@@ -48,7 +46,7 @@ public class SysMetaObjectHandler implements MetaObjectHandler {
if
(
StringUtils
.
isBlank
(
token
)){
throw
new
SysException
(
"token不能为空"
);
}
Object
currentUser
=
request
.
get
Session
().
get
Attribute
(
token
);
Object
currentUser
=
request
.
getAttribute
(
token
);
CurrentUser
user
=
null
;
if
(
ObjectUtils
.
isNotEmpty
(
currentUser
)){
user
=
SlmConstants
.
gson
.
fromJson
(
currentUser
.
toString
(),
CurrentUser
.
class
);
...
...
src/main/java/com/syc/slm/slmbi/controller/BaseRestController.java
View file @
a1ed68f6
...
...
@@ -85,7 +85,7 @@ public class BaseRestController {
String
getUrl
=
dcClientHost
+
"/{appId}/users/user-info"
;
R
<
CurrentUser
>
result
=
RestTemplateUtils
.
get
(
getUrl
,
new
TypeToken
<
R
<
CurrentUser
>>()
{
}.
getType
(),
uriVariables
);
request
.
getSession
().
setAttribute
(
token
,
SlmConstants
.
gson
.
toJson
(
result
.
detach
()));
request
.
setAttribute
(
token
,
SlmConstants
.
gson
.
toJson
(
result
.
detach
()));
}
...
...
@@ -100,6 +100,6 @@ public class BaseRestController {
protected
CurrentUser
getCurrentUser
(
HttpServletRequest
request
){
String
token
=
request
.
getHeader
(
SlmConstants
.
TOKEN_PREFIX
);
return
SlmConstants
.
gson
.
fromJson
(
request
.
get
Session
().
get
Attribute
(
token
).
toString
(),
CurrentUser
.
class
);
return
SlmConstants
.
gson
.
fromJson
(
request
.
getAttribute
(
token
).
toString
(),
CurrentUser
.
class
);
}
}
src/main/java/com/syc/slm/slmbi/handler/SysExceptionHandler.java
View file @
a1ed68f6
...
...
@@ -3,6 +3,7 @@ package com.syc.slm.slmbi.handler;
import
com.syc.slm.common.core.util.R
;
import
com.syc.slm.slmbi.exception.SysException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.mybatis.spring.MyBatisSystemException
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseBody
;
...
...
@@ -32,4 +33,16 @@ public class SysExceptionHandler {
return
R
.
bad
(
e
.
getMsg
(),
e
.
getDebugMsg
());
}
/**
* mybaits抛出的异常,以及SysMetaObjectHandler自定义抛出的异常
* @param e
* @return
*/
@ExceptionHandler
(
MyBatisSystemException
.
class
)
@ResponseBody
public
R
<
Object
>
handleMyBatisSystemException
(
MyBatisSystemException
e
)
{
log
.
info
(
e
.
getMessage
());
return
R
.
bad
(
e
.
getCause
().
getCause
().
getMessage
(),
e
.
getMessage
());
}
}
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