Commit 96a4bb21 by s_guodong

增加bigdecimal的检验

parent 1e68e2b7
package com.ceb.gjjs.mda.special.vo;
import com.brilliance.mda.runtime.annotation.Need;
import com.brilliance.mda.runtime.annotation.RelPath;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import java.io.Serializable;
/**
* @Description
* @Author s_guodong
* @Date 2023/8/10
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DemoListVo implements Serializable {
@JsonIgnore
private static final long serialVersionUID = 1L;
@Length(max = 20, message = "最大长度为20")
@RelPath("cur")
private String aa;
@Need
@RelPath("act")
private String bb;
}
package com.ceb.gjjs.mda.special.vo;
import com.brilliance.mda.runtime.annotation.RelPath;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import java.util.List;
/**
* @Description
* @Author s_guodong
* @Date 2023/8/11
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DemoResultVo extends RespondBaseVo {
@RelPath("acdgrp_rec_account")
private String acount;
private String b;
@RelPath("dataList")
private List<DemoListVo> data_list;
@RelPath("acd")
private DemoVo_2 acd_data;
@RelPath("addrs")
private List<String> addrLines;
}
package com.ceb.gjjs.mda.special.vo;
import com.brilliance.mda.runtime.annotation.Need;
import com.brilliance.mda.runtime.annotation.RelPath;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import java.io.Serializable;
import java.util.List;
/**
* @Description
* @Author s_guodong
* @Date 2023/8/10
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DemoVo extends RequestBaseVo implements Serializable {
@JsonIgnore
private static final long serialVersionUID = 1L;
@Length(max = 2, message = "最大长度为20")
@RelPath("acdgrp_rec_account")
private String a;
@Length(max = 2, message = "最大长度为2")
@Need
private String b;
@RelPath("dataList")
@Need
private List<DemoListVo> list;
@RelPath("acd")
@Need
private DemoVo_2 demoVo_2;
@RelPath("addrs")
@Need
private List<String> addrList;
}
package com.ceb.gjjs.mda.special.vo;
import com.brilliance.mda.runtime.annotation.Need;
import com.brilliance.mda.runtime.annotation.RelPath;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import java.io.Serializable;
/**
* @Description
* @Author s_guodong
* @Date 2023/8/10
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DemoVo_2 implements Serializable {
@JsonIgnore
private static final long serialVersionUID = 1L;
@Length(max = 20, message = "最大长度为20")
@RelPath("entname")
private String name;
@Length(max = 2, message = "最大长度为2")
@RelPath("inr")
private String addr;
}
package com.ceb.gjjs.mda.util;
import com.brilliance.mda.runtime.annotation.Need;
import com.brilliance.mda.support.jakson.serialize.DecimalLength;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.List;
/**
......@@ -27,17 +29,35 @@ public class ValidatorUtil {
o = f.get(obj);
} catch (IllegalAccessException e) {
}
if (f.isAnnotationPresent(Length.class) && type.isAssignableFrom(String.class)) {
if (f.isAnnotationPresent(Length.class)) {
Length length = f.getAnnotation(Length.class);
int min = length.min();
int max = length.max();
String message = length.message();
if (o != null) {
String stringValue = (String) o;
if (stringValue.length() > max || stringValue.length() < min) {
return "参数校验错误[" + f.getName() + ":" + message + "]";
if (type.isAssignableFrom(String.class)) {
int min = length.min();
String stringValue = (String) o;
if (stringValue.length() > max || stringValue.length() < min) {
return "参数校验错误[" + f.getName() + ":" + message + "]";
}
} else if (type.isAssignableFrom(BigDecimal.class)) {
String bigDecimal = o.toString();
String replace = bigDecimal.replace(".", "");
if (replace.length() > max) {
return "参数校验错误[" + f.getName() + ":" + message + "]";
}
if (f.isAnnotationPresent(DecimalLength.class)) {
DecimalLength annotation = f.getAnnotation(DecimalLength.class);
int i = bigDecimal.indexOf(".");
String substring = bigDecimal.substring(i + 1);
if (substring.length() > annotation.value()) {
return "参数校验错误[" + f.getName() + ":小数点最大" + annotation.value() + "]";
}
}
}
}
}
if (f.isAnnotationPresent(NotEmpty.class) && type.isAssignableFrom(String.class)) {
if (o == null || StringUtils.isBlank((String) o)) {
......
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