【问题标题】:Messages not translating into different language in STS thymeleaf未在 STS thymeleaf 中翻译成不同语言的消息
【发布时间】:2021-11-24 19:27:21
【问题描述】:
在 Spring Boot 中,为了验证 thymeleaf 形式的字段,我有多种语言,所以
当我将表单翻译成不同的形式时,我的验证消息并未将其显示在
英语。
我对每种语言都有不同的属性文件。
由于我的表格翻译成不同的语言,如果我改变语言,只有问题是
验证消息显示在屏幕上。
@NotEmpty(message = "{city.notblank}")
@Size(min = 1, max=100)
protected String city = "";
【问题讨论】:
标签:
java
spring-boot
thymeleaf
dto
notnull
【解决方案1】:
您需要配置 Spring Boot 以使用错误消息的消息源。将此 bean 添加到您的应用程序中:
@Bean
public LocalValidatorFactoryBean localValidatorFactoryBean(MessageSource messageSource) {
LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
bean.setValidationMessageSource(messageSource);
return bean;
}