BAEL-2966
This commit is contained in:
parent
2070c94ee9
commit
1889628daa
@ -0,0 +1,17 @@
|
||||
package com.baeldung.interpolation;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
public class NotNullRequest {
|
||||
|
||||
@NotNull(message = "stringValue has to be present")
|
||||
private String stringValue;
|
||||
|
||||
public String getStringValue() {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
public void setStringValue(String stringValue) {
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.baeldung.interpolation;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class RestController {
|
||||
|
||||
@PostMapping("/test-not-null")
|
||||
public void testNotNull(@Valid @RequestBody NotNullRequest request) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.baeldung.interpolation;
|
||||
|
||||
import java.util.Formatter;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.DecimalMin;
|
||||
|
||||
public class ValidationExamples {
|
||||
|
||||
private static final Formatter formatter = new Formatter();
|
||||
|
||||
@Size(
|
||||
min = 5,
|
||||
max = 14,
|
||||
message = "The author email '${validatedValue}' must be between {min} and {max} characters long"
|
||||
)
|
||||
private String authorEmail;
|
||||
|
||||
@Min(
|
||||
value = 1,
|
||||
message = "There must be at least {value} test{value > 1 ? 's' : ''} int the test case"
|
||||
)
|
||||
private int testCount;
|
||||
|
||||
@DecimalMin(
|
||||
value = "50",
|
||||
message = "The code coverage ${formatter.format('%1$.2f', validatedValue)} must be higher than {value}%"
|
||||
)
|
||||
private double codeCoverage;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user