zoukankan      html  css  js  c++  java
  • freemarker使用的一些问题

    1.spring mvc集成乱码问题(红色背景部分配置)

    <bean id="freemarkerConfig"
            class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
            <property name="templateLoaderPath" value="/WEB-INF/views/" />
            <property name="freemarkerSettings">  
              <props>  
                  <prop key="defaultEncoding">UTF-8</prop>  
              </props>  
          </property>  
        </bean>
    
        <bean id="viewResolver"
            class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
            <property name="cache" value="false" />
            <property name="prefix" value="" />
            <property name="suffix" value=".html" />
            <property name="contentType" value="text/html;charset=UTF-8"></property> 
        </bean>

    2.变量未赋值,或者值为null时抛出异常问题

    ${变量名!}

    3.取变量属性的属性,但是变量可能为null

    ${(变量名.属性.属性)!}

    4.日期格式

    ${date?string("yyyy-MM-dd HH:mm:ss")}

    5.日期属性为null防止格式异常

    ${(date?string("yyyy-MM-dd HH:mm:ss"))!}

    6.属性为null时显示默认值

    ${属性!默认值}

     7.spring mvc中取出请求中的参数(只在spring mvc中测试过)

    ${RequestParameters.参数名称!}

  • 相关阅读:
    java中字符串类型的比较
    iOS 检测是否插入耳机
    Model-View-Controller (The iPhone Developer's Cookbook)
    Spring Animation
    CoreImage 自动增强滤镜 以及 系统滤镜查询
    UIView Animation
    CoreImage 查询系统滤镜
    CoreImage 的人脸检测
    Smarty 模板操作
    smarty转载(1)
  • 原文地址:https://www.cnblogs.com/moqi2013/p/3682448.html
Copyright © 2011-2022 走看看