Created
June 17, 2018 04:14
-
-
Save sirius2k/52ba50c5464e6c45c4b3952997bb37aa to your computer and use it in GitHub Desktop.
SpringBoot BeanValidator custom messages from MessageSource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
validation.id.NotEmpty=ID is required. | |
validation.id.Size=ID must be minimum 4 and maximum 20 characters. | |
validation.id.Pattern=ID must start with alphabet and contain alphanumeric characters. | |
validation.email.NotEmpty=email is required. | |
validation.email.Email=Not an valid email format. | |
validation.password.NotEmpty=password is required. | |
validation.password.Size=Password must be minimum 8 and maximum 30 characters. | |
validation.password.Pattern=Password must contain at least 1 numeric, 1 alphabet, 1 capital letter and special character. | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
validation.id.NotEmpty=ID는 필수 입력사항입니다. | |
validation.id.Size=ID는 4자이상 20자 이하입니다. | |
validation.id.Pattern=ID는 4자이상 20자 이하입니다. | |
validation.email.NotEmpty=이메일은 필수 입력사항입니다. | |
validation.email.Email=이메일 형식이 올바르지 않습니다. | |
validation.password.NotEmpty=비밀번호는 필수 입력사항입니다. | |
validation.password.Size=비밀번호는 8자이상 20자 이하입니다. | |
validation.password.Pattern=비말번호는 최소 1글자의 영문 대문자, 숫자, 특수문자가 포함되어 있어야 합니다. | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Data | |
@NoArgsConstructor | |
@AllArgsConstructor | |
public class SignupForm { | |
@NotEmpty(message = "{validation.id.NotEmpty}") | |
@Pattern(regexp = "^[a-zA-Z]{1}[a-zA-Z0-9_]{4,20}$", message = "{validation.id.Pattern}") | |
private String id; | |
@NotEmpty(message = "{validation.email.NotEmpty}") | |
@Email(message = "{validation.email.Email}") | |
private String email; | |
@NotEmpty(message = "{validation.password.NotEmpty}") | |
@Pattern(regexp = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&+=])(?=\\S+$).{8,20}$", message = "{validation.password.Pattern}") | |
private String password; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class ValidatorConfig { | |
@Bean | |
public LocalValidatorFactoryBean localValidatorFactoryBean(MessageSource messageSource) { | |
LocalValidatorFactoryBean factory = new LocalValidatorFactoryBean(); | |
factory.setValidationMessageSource(messageSource); | |
return factory; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment