我有一个 SpringBoot 应用程序。使用具有此属性的 bean:
@Positive(message = "{signup.form.error.city.missing}")
private Long regionId;
但如果出现错误,我会在浏览器上看到:
{signup.form.error.city.missing}
不是属性文件的值
答案 0 :(得分:1)
要在属性文件中使用自定义名称消息,例如需要定义 (startX, startY, endX, endY) = rect
startX = int(startX * W)
startY = int(startY * H)
endX = int(endX * W)
endY = int(endY * H)
cv2.rectangle(frame, (startX, startY), (endX, endY), (155, 255, 0), 2)
并注册 LocalValidatorFactoryBean
:
messageSource
它现在将看到您在 import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
@Configuration
public class WebMvcConfiguration {
private final MessageSource messageSource;
public WebMvcConfiguration(MessageSource messageSource) {
this.messageSource = messageSource;
}
@Bean
public LocalValidatorFactoryBean getValidator() {
LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
bean.setValidationMessageSource(messageSource);
return bean;
}
}
文件中定义的值。