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
974e9efd
Commit
974e9efd
authored
Nov 10, 2023
by
s_guodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.参数校验提示修改
2.返回前端时null值处理
parent
22dabe67
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
10 deletions
+63
-10
JsonConfig.java
...ess/src/main/java/com/ceb/gjjs/mda/config/JsonConfig.java
+5
-0
NullValueSerializer.java
...ain/java/com/ceb/gjjs/mda/config/NullValueSerializer.java
+21
-0
ReflectUtil.java
...ness/src/main/java/com/ceb/gjjs/mda/util/ReflectUtil.java
+22
-0
ValidatorUtil.java
...ss/src/main/java/com/ceb/gjjs/mda/util/ValidatorUtil.java
+11
-8
Need.java
...main/java/com/brilliance/mda/runtime/annotation/Need.java
+1
-1
DecimalLength.java
...rilliance/mda/support/jakson/serialize/DecimalLength.java
+3
-1
No files found.
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/config/JsonConfig.java
View file @
974e9efd
...
...
@@ -3,6 +3,7 @@ package com.ceb.gjjs.mda.config;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.databind.SerializerProvider
;
import
com.fasterxml.jackson.databind.module.SimpleModule
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -34,6 +35,10 @@ public class JsonConfig {
// 日期格式处理
// objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
// 处理null值
SerializerProvider
serializerProvider
=
objectMapper
.
getSerializerProvider
();
serializerProvider
.
setNullValueSerializer
(
NullValueSerializer
.
instance
);
return
objectMapper
;
}
...
...
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/config/NullValueSerializer.java
0 → 100644
View file @
974e9efd
package
com
.
ceb
.
gjjs
.
mda
.
config
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.databind.JsonSerializer
;
import
com.fasterxml.jackson.databind.SerializerProvider
;
import
java.io.IOException
;
/**
* @Description
* @Author s_guodong
* @Date 2023/11/10
*/
public
class
NullValueSerializer
extends
JsonSerializer
<
Object
>
{
public
static
final
NullValueSerializer
instance
=
new
NullValueSerializer
();
@Override
public
void
serialize
(
Object
value
,
JsonGenerator
jsonGenerator
,
SerializerProvider
serializerProvider
)
throws
IOException
{
jsonGenerator
.
writeObject
(
""
);
}
}
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/util/ReflectUtil.java
View file @
974e9efd
...
...
@@ -13,6 +13,7 @@ import java.lang.reflect.ParameterizedType;
import
java.lang.reflect.Type
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -109,6 +110,7 @@ public class ReflectUtil {
declaredField
.
setAccessible
(
true
);
Object
o
=
declaredField
.
get
(
baseVo
);
if
(
o
==
null
)
{
setEmptyValue
(
f
,
respondVo
);
continue
;
}
Class
<?>
type
=
declaredField
.
getType
();
...
...
@@ -203,4 +205,24 @@ public class ReflectUtil {
}
/**
* 值为null时设置空值
*
* @param f
* @param respondVo
*/
private
static
void
setEmptyValue
(
Field
f
,
Object
respondVo
)
throws
IllegalAccessException
{
Class
tType
=
f
.
getType
();
if
(
tType
.
isAssignableFrom
(
BigDecimal
.
class
))
{
f
.
set
(
respondVo
,
new
BigDecimal
(
"0"
));
}
else
if
(
tType
.
isAssignableFrom
(
Double
.
TYPE
)
||
tType
.
isAssignableFrom
(
Double
.
class
))
{
f
.
set
(
respondVo
,
0
D
);
}
else
if
(
tType
.
isAssignableFrom
(
Integer
.
TYPE
)
||
tType
.
isAssignableFrom
(
Integer
.
class
))
{
f
.
set
(
respondVo
,
0
);
}
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 @
974e9efd
...
...
@@ -38,13 +38,13 @@ public class ValidatorUtil {
int
min
=
length
.
min
();
String
stringValue
=
(
String
)
o
;
if
(
stringValue
.
length
()
>
max
||
stringValue
.
length
()
<
min
)
{
return
"参数校验错误["
+
f
.
getName
()
+
":"
+
message
+
"]"
;
return
"参数校验错误["
+
message
+
"]"
;
}
}
else
if
(
type
.
isAssignableFrom
(
BigDecimal
.
class
))
{
String
bigDecimal
=
((
BigDecimal
)
o
).
toPlainString
();
String
replace
=
bigDecimal
.
replace
(
"."
,
""
);
if
(
replace
.
length
()
>
max
)
{
return
"参数校验错误["
+
f
.
getName
()
+
":"
+
message
+
"]"
;
return
"参数校验错误["
+
message
+
"]"
;
}
if
(
f
.
isAnnotationPresent
(
DecimalLength
.
class
))
{
DecimalLength
annotation
=
f
.
getAnnotation
(
DecimalLength
.
class
);
...
...
@@ -52,7 +52,7 @@ public class ValidatorUtil {
if
(
i
>
-
1
)
{
String
substring
=
bigDecimal
.
substring
(
i
+
1
);
if
(
substring
.
length
()
>
annotation
.
value
())
{
return
"参数校验错误["
+
f
.
getName
()
+
":小数点最大"
+
annotation
.
valu
e
()
+
"]"
;
return
"参数校验错误["
+
annotation
.
messag
e
()
+
"]"
;
}
}
}
...
...
@@ -62,28 +62,31 @@ public class ValidatorUtil {
}
if
(
f
.
isAnnotationPresent
(
NotEmpty
.
class
)
&&
type
.
isAssignableFrom
(
String
.
class
))
{
NotEmpty
annotation
=
f
.
getAnnotation
(
NotEmpty
.
class
);
if
(
o
==
null
||
StringUtils
.
isBlank
((
String
)
o
))
{
return
"参数校验错误["
+
f
.
getName
()
+
":不能为空
]"
;
return
"参数校验错误["
+
annotation
.
message
()
+
"
]"
;
}
}
if
(
f
.
isAnnotationPresent
(
NotNull
.
class
)
&&
!
type
.
isAssignableFrom
(
String
.
class
))
{
NotNull
annotation
=
f
.
getAnnotation
(
NotNull
.
class
);
if
(
o
==
null
)
{
return
"参数校验错误["
+
f
.
getName
()
+
":不能为null
]"
;
return
"参数校验错误["
+
annotation
.
message
()
+
"
]"
;
}
}
if
(
f
.
isAnnotationPresent
(
Need
.
class
))
{
Need
annotation
=
f
.
getAnnotation
(
Need
.
class
);
if
(
o
==
null
)
{
return
"参数校验错误["
+
f
.
getName
()
+
":为必需参数
]"
;
return
"参数校验错误["
+
annotation
.
message
()
+
"
]"
;
}
if
(
type
.
isAssignableFrom
(
String
.
class
)
&&
StringUtils
.
isBlank
((
String
)
o
))
{
return
"参数校验错误["
+
f
.
getName
()
+
":为必需参数,不能为空
]"
;
return
"参数校验错误["
+
annotation
.
message
()
+
"
]"
;
}
if
(
ReflectUtil
.
isPrimate
(
type
))
{
}
else
if
(
"java.util.List"
.
equals
(
type
.
getName
()))
{
List
list
=
(
List
)
o
;
if
(
list
.
size
()
==
0
)
{
return
"参数校验错误["
+
f
.
getName
()
+
":元素个数不能为0
]"
;
return
"参数校验错误["
+
annotation
.
message
()
+
"
]"
;
}
// 获取list的泛型
Class
tType
=
ReflectUtil
.
getTType
(
f
);
...
...
gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/annotation/Need.java
View file @
974e9efd
...
...
@@ -12,5 +12,5 @@ public @interface Need {
boolean
value
()
default
true
;
String
message
()
default
"不能为空"
;
String
message
()
default
"
必填项
不能为空"
;
}
gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/jakson/serialize/DecimalLength.java
View file @
974e9efd
...
...
@@ -6,6 +6,8 @@ import java.lang.annotation.*;
@Target
(
ElementType
.
FIELD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
DecimalLength
{
public
int
value
()
default
0
;
int
value
()
default
0
;
String
message
()
default
""
;
}
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