zoukankan      html  css  js  c++  java
  • spring MVC整合freemarker

    依赖包:

    freemarker.jar

    springMVC-servlet.xml文件内容:

    <bean id="viewResolver"  
            class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">  
            <property name="cache" value="true" />  
            <property name="prefix" value="" />  
            <property name="suffix" value=".ftl" />  
            <property name="contentType" value="text/html;charset=UTF-8"></property>  
            <property name="requestContextAttribute" value="request" />  
            <property name="exposeSpringMacroHelpers" value="true" />  
            <property name="exposeRequestAttributes" value="true" />  
            <property name="exposeSessionAttributes" value="true" />  
        </bean>

    这里其实没什么特别的地方就是实现了一个bean

    spring.xml(applicationContext.xml)文件内容:

    <!-- freemarker的配置 -->
        <bean id="freemarkerConfig"
            class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
            <property name="templateLoaderPath" value="/WEB-INF/page/" />
        <!--上下文地址的获取-->
    <property name="freemarkerVariables"> <map> <entry key="base" value="#{servletContext.contextPath}" /> </map> </property> <property name="defaultEncoding" value="utf-8" /> <property name="freemarkerSettings"> <props> <prop key="template_update_delay">10</prop> <prop key="locale">zh_CN</prop> <prop key="datetime_format">yyyy-MM-dd</prop><!-- 时间格式化 --> <prop key="date_format">yyyy-MM-dd</prop> <prop key="number_format">#.##</prop> </props> </property> </bean>

    我这里spring的配置文件名为spring.xml这是个人习惯问题,Struts的小伙伴应该更习惯applicationContext.xml的叫法

    这是只是最基本的整合其余的扩展大家可以在进一步交流。。。。。。

  • 相关阅读:
    Windows下Jupyter notebook 更改工作目录
    AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas
    python中sorted函数
    U3d学习001-RollBox例子
    猴哥来了-游戏开发记录17-微信排行榜bug
    写在自己40岁生日,勉励自己,再度出发!
    python网页爬虫开发之一
    python学习笔记之二
    python学习笔记之一
    conda和pip环境管理
  • 原文地址:https://www.cnblogs.com/zhangchengbing/p/6957386.html
Copyright © 2011-2022 走看看