Merge pull request #7716 from MajewskiKrzysztof/BAEL-BAEL-2966
BAEL-2966
This commit is contained in:
commit
6c2f862dcb
@ -0,0 +1,29 @@
|
||||
package com.baeldung.interpolation;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import javax.validation.MessageInterpolator;
|
||||
import java.util.Locale;
|
||||
|
||||
public class MyMessageInterpolator implements MessageInterpolator {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(MyMessageInterpolator.class);
|
||||
|
||||
private final MessageInterpolator defaultInterpolator;
|
||||
|
||||
public MyMessageInterpolator(MessageInterpolator interpolator) {
|
||||
this.defaultInterpolator = interpolator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String interpolate(String messageTemplate, Context context) {
|
||||
messageTemplate = messageTemplate.toUpperCase();
|
||||
return defaultInterpolator.interpolate(messageTemplate, context, Locale.getDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String interpolate(String messageTemplate, Context context, Locale locale) {
|
||||
messageTemplate = messageTemplate.toUpperCase();
|
||||
return defaultInterpolator.interpolate(messageTemplate, context, locale);
|
||||
}
|
||||
}
|
@ -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 ValidationController {
|
||||
|
||||
@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' : ''} in 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