In a .jsp I would use:
<fmt:message key="welcome.title"/>
to display a message from my messages.properties file.
How would I do this with freemarker ?
Comments: <#-- and --> Comments are similar to HTML comments, but they are delimited by <#-- and -->. Comments will be ignored by FreeMarker, and will not be written to the output.
The spring-boot-starter-freemarker is starter for building Spring MVC applications with FreeMarker. The spring-boot-starter-jdbc is a starter for using JDBC in Spring Boot. This is City bean class. It contains item id, name, and population.
FreeMarker is a Java based template engine from the Apache Software Foundation. Like other template engines, FreeMarker is designed to support HTML web pages in applications following the MVC pattern. This tutorial illustrates how to configure FreeMarker for use in Spring MVC as an alternative to JSP.
FreeMarker is a Template Engine. it is provided by Apache as an open source Java library. The FreeMarker reads sample files and combines them with Java objects to generate an output text (html, email, ..).
Import Spring Macro
<#import "/spring.ftl" as spring/>
Then
<@spring.message "yourMessageKeyGoesHere"/>
But you need to register ResourceBundleMessageSource
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages"/>
</bean>
Keep in mind MessageSource must be called messageSource
@Blankman
No, you don't have to import this manually in each template. You can set an auto_import property in your freemarker settings as showed below.
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
...
<property name="freemarkerSettings">
<props>
<prop key="auto_import">spring.ftl as spring</prop>
</props>
</property>
</bean>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With