Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjjs-bd-common
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
s_guodong
gjjs-bd-common
Commits
007035bd
Commit
007035bd
authored
Nov 13, 2023
by
s_guodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.增加时间校验
2.优化返回前端时null值处理
parent
974e9efd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
1 deletions
+60
-1
JsonConfig.java
...ess/src/main/java/com/ceb/gjjs/mda/config/JsonConfig.java
+3
-0
MyDateDeSerialized.java
...main/java/com/ceb/gjjs/mda/config/MyDateDeSerialized.java
+47
-0
RespondBaseVo.java
.../main/java/com/ceb/gjjs/mda/special/vo/RespondBaseVo.java
+1
-1
ReflectUtil.java
...ness/src/main/java/com/ceb/gjjs/mda/util/ReflectUtil.java
+2
-0
ValidatorUtil.java
...ss/src/main/java/com/ceb/gjjs/mda/util/ValidatorUtil.java
+7
-0
No files found.
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/config/JsonConfig.java
View file @
007035bd
...
...
@@ -9,6 +9,8 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
;
import
java.util.Date
;
@Configuration
public
class
JsonConfig
{
...
...
@@ -26,6 +28,7 @@ public class JsonConfig {
SimpleModule
simpleModule
=
new
SimpleModule
();
simpleModule
.
addSerializer
(
Long
.
class
,
com
.
fasterxml
.
jackson
.
databind
.
ser
.
std
.
ToStringSerializer
.
instance
);
simpleModule
.
addSerializer
(
Long
.
TYPE
,
com
.
fasterxml
.
jackson
.
databind
.
ser
.
std
.
ToStringSerializer
.
instance
);
simpleModule
.
addDeserializer
(
Date
.
class
,
new
MyDateDeSerialized
());
objectMapper
.
registerModule
(
simpleModule
);
// 反序列化的时候如果多了其他属性,不抛出异常
...
...
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/config/MyDateDeSerialized.java
0 → 100644
View file @
007035bd
package
com
.
ceb
.
gjjs
.
mda
.
config
;
import
com.brilliance.eibs.util.StringUtil
;
import
com.ceb.gjjs.mda.util.ValidatorUtil
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.databind.DeserializationContext
;
import
com.fasterxml.jackson.databind.JsonDeserializer
;
import
javax.validation.constraints.Pattern
;
import
java.io.IOException
;
import
java.lang.reflect.Field
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
public
class
MyDateDeSerialized
extends
JsonDeserializer
{
@Override
public
Object
deserialize
(
JsonParser
p
,
DeserializationContext
ctxt
)
throws
IOException
{
Date
date
=
null
;
String
source
=
p
.
getText
().
trim
();
String
currentName
=
p
.
getCurrentName
();
Object
currentValue
=
p
.
getCurrentValue
();
Class
<?>
aClass
=
currentValue
.
getClass
();
Field
declaredField
=
null
;
try
{
declaredField
=
aClass
.
getDeclaredField
(
currentName
);
}
catch
(
NoSuchFieldException
e
)
{
}
declaredField
.
setAccessible
(
true
);
if
(
StringUtil
.
isNotEmpty
(
source
))
{
String
format
=
declaredField
.
getAnnotation
(
JsonFormat
.
class
).
pattern
();
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
format
);
try
{
date
=
simpleDateFormat
.
parse
(
source
);
}
catch
(
ParseException
e
)
{
Pattern
patternAnnotation
=
declaredField
.
getAnnotation
(
Pattern
.
class
);
ValidatorUtil
.
CHECK_ERR_MSG
.
set
(
patternAnnotation
==
null
?
"时间格式不正确"
:
patternAnnotation
.
message
());
return
null
;
}
}
return
date
;
}
}
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/special/vo/RespondBaseVo.java
View file @
007035bd
...
...
@@ -11,9 +11,9 @@ import java.io.Serializable;
* @Author s_guodong
* @Date 2023/8/10
*/
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@Data
public
class
RespondBaseVo
implements
Serializable
{
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
private
String
total
;
}
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/util/ReflectUtil.java
View file @
007035bd
...
...
@@ -219,6 +219,8 @@ public class ReflectUtil {
f
.
set
(
respondVo
,
0
D
);
}
else
if
(
tType
.
isAssignableFrom
(
Integer
.
TYPE
)
||
tType
.
isAssignableFrom
(
Integer
.
class
))
{
f
.
set
(
respondVo
,
0
);
}
else
if
(
tType
.
isAssignableFrom
(
String
.
class
))
{
f
.
set
(
respondVo
,
""
);
}
else
if
(
tType
.
isAssignableFrom
(
List
.
class
))
{
f
.
set
(
respondVo
,
Collections
.
EMPTY_LIST
);
}
...
...
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/util/ValidatorUtil.java
View file @
007035bd
package
com
.
ceb
.
gjjs
.
mda
.
util
;
import
com.brilliance.eibs.util.StringUtil
;
import
com.brilliance.mda.runtime.annotation.Need
;
import
com.brilliance.mda.support.jakson.serialize.DecimalLength
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -17,8 +18,14 @@ import java.util.List;
* @Date 2023/8/8
*/
public
class
ValidatorUtil
{
public
static
final
ThreadLocal
<
String
>
CHECK_ERR_MSG
=
new
ThreadLocal
<>();
public
static
String
check
(
Object
obj
)
{
if
(
StringUtil
.
isNotEmpty
(
CHECK_ERR_MSG
.
get
()))
{
String
s
=
CHECK_ERR_MSG
.
get
();
CHECK_ERR_MSG
.
remove
();
return
"参数校验错误["
+
s
+
"]"
;
}
Class
<?>
aClass
=
obj
.
getClass
();
Field
[]
fields
=
aClass
.
getDeclaredFields
();
for
(
Field
f
:
fields
)
{
...
...
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