how to use messages with freemarker in spring mvc?

前端 未结 3 1342
攒了一身酷
攒了一身酷 2020-12-14 18:13

In a .jsp I would use:


to display a message from my messages.properties file.

How would

3条回答
  •  时光取名叫无心
    2020-12-14 18:44

    Others are fine answers. Providing java config as example for those that use that.

     @Bean(name = "freemarkerConfig")
    public FreeMarkerConfigurer freemarkerConfig() {
        FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
        configurer.setTemplateLoaderPaths("/WEB-INF/views/", 'classpath:/templates');
        Map map = new HashMap<>();
        map.put("xml_escape", new XmlEscape());
        configurer.setFreemarkerVariables(map)
        def settings = new Properties()
        settings['auto_import']  =  'spring.ftl as spring,layout/application.ftl as l,/macros/meh.ftl as meh'
        configurer.setFreemarkerSettings(settings)
        log.info "returning freemarker config"
        return configurer;
    }
    

提交回复
热议问题