java - 如何在spring mvc中使用带有freemarker的消息?

在 .jsp 中我会使用:

<fmt:message key="welcome.title"/>

显示来 self 的 messages.properties 文件的消息。

我将如何使用 freemarker 做到这一点?

最佳答案

导入 Spring 宏

<#import "/spring.ftl" as spring/>

然后

<@spring.message "yourMessageKeyGoesHere"/>

但是你需要注册ResourceBundleMessageSource

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="messages"/>
</bean>

记住 MessageSource 必须调用 messageSource

https://stackoverflow.com/questions/3154804/

相关文章:

java - SpringBoot - BeanDefinitionOverrideExceptio

java - servlet 映射 url 模式上的双通配符 (*) 是什么意思?

java - Spring Boot 是否可以使用 JAR 包装来提供 JSP?

spring - 是否可以在表单 :select/form:option 的 itemLabel 中

java - 使用 Spring 将文本文件直接注入(inject) String

spring - Thymeleaf - 使用 PUBLICID "null"请求的不受支持的实体

java - Spring Security 中的 "principal"是什么?

java - 使用 restAssured 测试 Spring Boot Rest 应用程序

java - 通过 Spring 将字段注入(inject) Hibernate 加载的实体中

database - Spring Batch Framework - 自动创建批处理表