【问题标题】:JSR-303/JSR-349 message key in Spring MVC 4Spring MVC 4 中的 JSR-303/JSR-349 消息键
【发布时间】:2016-03-07 19:55:55
【问题描述】:

我有一个应用程序(使用注释的 Spring MVC 4 + Hibernate/JPA + MySQL + Maven 集成示例),使用基于注释的配置将 Spring 与 Hibernate 集成。

我有这个属性

 @Pattern(regexp = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
            + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$", 
            message = "{general.error.mail}")
    private String email;

但是当出现错误时,我会在页面中看到键而不是消息本身

 {general.error.mail}

【问题讨论】:

  • 你在哪里添加了消息键的值?添加您的配置和项目结构

标签: spring jsp spring-mvc bean-validation


【解决方案1】:

您需要一个 messages.properties 文件。查看Spring MVC Form Validation Example with Bean Validation API 作为教程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    • 2015-07-30
    • 2011-05-10
    • 2016-01-20
    • 2012-08-20
    • 2018-08-15
    • 2011-07-24
    相关资源
    最近更新 更多