Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 768cc8a

Browse files
committedMar 15, 2019
changing error code data type
1 parent bd1d350 commit 768cc8a

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
lines changed
 

‎fluent-validator-demo/pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@
6767
</dependency>
6868

6969
<!-- test dependencies -->
70-
<dependency>
71-
<groupId>org.springframework</groupId>
72-
<artifactId>spring-test</artifactId>
73-
</dependency>
74-
7570
<dependency>
7671
<groupId>commons-lang</groupId>
7772
<artifactId>commons-lang</artifactId>

‎fluent-validator-jsr303/src/main/java/com/baidu/unbiz/fluentvalidator/jsr303/HibernateSupportedValidator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class HibernateSupportedValidator<T> extends ValidatorHandler<T> implemen
3030
/**
3131
* hibernate默认的错误码
3232
*/
33-
private int hibernateDefaultErrorCode;
33+
private String hibernateDefaultErrorCode;
3434

3535
/**
3636
* {@link ConstraintViolation}到{@link ValidationError}的转换器
@@ -85,7 +85,7 @@ public HibernateSupportedValidator<T> setHibernateValidator(javax.validation.Val
8585
return this;
8686
}
8787

88-
public HibernateSupportedValidator<T> setHibernateDefaultErrorCode(int hibernateDefaultErrorCode) {
88+
public HibernateSupportedValidator<T> setHibernateDefaultErrorCode(String hibernateDefaultErrorCode) {
8989
this.hibernateDefaultErrorCode = hibernateDefaultErrorCode;
9090
return this;
9191
}

‎fluent-validator/src/main/java/com/baidu/unbiz/fluentvalidator/ValidationError.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class ValidationError {
2626
/**
2727
* 错误码
2828
*/
29-
private int errorCode;
29+
private String errorCode;
3030

3131
/**
3232
* 错误值
@@ -54,11 +54,11 @@ public static ValidationError create(String errorMsg) {
5454
return new ValidationError().setErrorMsg(errorMsg);
5555
}
5656

57-
public int getErrorCode() {
57+
public String getErrorCode() {
5858
return errorCode;
5959
}
6060

61-
public ValidationError setErrorCode(int errorCode) {
61+
public ValidationError setErrorCode(String errorCode) {
6262
this.errorCode = errorCode;
6363
return this;
6464
}

‎fluent-validator/src/test/java/com/baidu/unbiz/fluentvalidator/FluentValidatorStringTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void testStringComplexResultNegative() {
5959
System.out.println(ret);
6060
System.out.println(ret.getTimeElapsed());
6161
assertThat(ret.isSuccess(), is(false));
62-
assertThat(ret.getErrors().get(0).getErrorCode(), is(100));
62+
assertThat(ret.getErrors().get(0).getErrorCode(), is("100"));
6363
assertThat(ret.getErrors().get(0).getErrorMsg(), is("string should be abc"));
6464
assertThat(ret.getErrors().get(0).getField(), is("str"));
6565
assertThat(ret.getErrors().get(0).getInvalidValue(), is((Object) str));
@@ -124,7 +124,7 @@ public MyError apply(ValidationError input) {
124124
System.out.println(ret);
125125
assertThat(ret.hasNoError(), is(false));
126126
assertThat(ret.getErrors().size(), is(1));
127-
assertThat(ret.getErrors().get(0).errorCode, is(100));
127+
assertThat(ret.getErrors().get(0).errorCode, is("100"));
128128
assertThat(ret.getErrors().get(0).errorMsg, is("string should be abc"));
129129
assertThat(ret.getErrors().get(0).field, is("str"));
130130
assertThat(ret.getErrors().get(0).invalidValue, is((Object) str));
@@ -176,7 +176,7 @@ class MyError {
176176
/**
177177
* 错误码
178178
*/
179-
public int errorCode;
179+
public String errorCode;
180180

181181
/**
182182
* 错误值

‎fluent-validator/src/test/java/com/baidu/unbiz/fluentvalidator/validator/StringValidator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public boolean validate(ValidatorContext context, String t) {
2424
}
2525
System.out.println("check " + t);
2626
if (!t.startsWith("abc")) {
27-
context.addError(ValidationError.create("string should be abc").setErrorCode(100).setField("str")
27+
context.addError(ValidationError.create("string should be abc").setErrorCode("100").setField("str")
2828
.setInvalidValue(t));
2929
return false;
3030
}

0 commit comments

Comments
 (0)
This repository has been archived.