Commit a3187b94 by s_guodong

BigDecimal参数校验优化

parent 8404467e
...@@ -41,7 +41,7 @@ public class ValidatorUtil { ...@@ -41,7 +41,7 @@ public class ValidatorUtil {
return "参数校验错误[" + f.getName() + ":" + message + "]"; return "参数校验错误[" + f.getName() + ":" + message + "]";
} }
} else if (type.isAssignableFrom(BigDecimal.class)) { } else if (type.isAssignableFrom(BigDecimal.class)) {
String bigDecimal = o.toString(); String bigDecimal = ((BigDecimal) o).toPlainString();
String replace = bigDecimal.replace(".", ""); String replace = bigDecimal.replace(".", "");
if (replace.length() > max) { if (replace.length() > max) {
return "参数校验错误[" + f.getName() + ":" + message + "]"; return "参数校验错误[" + f.getName() + ":" + message + "]";
...@@ -49,9 +49,11 @@ public class ValidatorUtil { ...@@ -49,9 +49,11 @@ public class ValidatorUtil {
if (f.isAnnotationPresent(DecimalLength.class)) { if (f.isAnnotationPresent(DecimalLength.class)) {
DecimalLength annotation = f.getAnnotation(DecimalLength.class); DecimalLength annotation = f.getAnnotation(DecimalLength.class);
int i = bigDecimal.indexOf("."); int i = bigDecimal.indexOf(".");
String substring = bigDecimal.substring(i + 1); if (i > -1) {
if (substring.length() > annotation.value()) { String substring = bigDecimal.substring(i + 1);
return "参数校验错误[" + f.getName() + ":小数点最大" + annotation.value() + "]"; if (substring.length() > annotation.value()) {
return "参数校验错误[" + f.getName() + ":小数点最大" + annotation.value() + "]";
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment