FreeMarker

springmvc.xml

<!-- 配置freemarker -->
    <bean id="freemarkerConfig"
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        <property name="templateLoaderPath" value="/WEB-INF/ftl/" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>
    <!-- freemarker视图解析器 -->
    <bean
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
        <property name="viewClass"  value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
        <property name="contentType" value="text/html; charset=utf-8" />
        <property name="suffix" value=".ftl" />
        <property name="order" value="0" />
    </bean>

hello.ftl

${name}

Controller

 @RequestMapping(value = "freemarker", method = RequestMethod.GET)
    public String index(Model model) {
        model.addAttribute("name", "Hello World");
        return "/hello";
    }

 http://localhost:8081/freemarker/

 

posted @ 2018-03-03 12:34  ~沐风  阅读(188)  评论(0编辑  收藏  举报