• freemarker规范


    1、循环问题:相当于jstl的foreach

    例子如下:

    <#if list?exists>                       //判断是否为空的list对象
         <#list list as parent>           //循环对象 list为从后台传来的对象   parent作为别名
           <li>${parent.parentName}:
                <#list parent.children as child>
                           <#if child.propertyId == 0>    //判断某个属性的id是否等于0 
                                 ${child.value}&nbsp;
                           </#if>
                          <#if child.propertyId != 0>    
                                ${child.childrenName}&nbsp;
                         </#if>
             </#list>
         </li>
    </#list>
    </#if>

    2、if 和else:相当于jstl的if或者choose

    <#list imageList as imagesList>
          <#if imagesList.id == 0>
              <li> 啊啊啊啊啊 </li>

           <#else>

                 <li> 啊啊啊啊啊 </li>         
           </#if>
    </#list>

    3、字符串截取相关

    <#if   news.title?length   lt   13   >  //判断要截取字符长度‘lt’小于 
      {news.title} 

     <#else>                                                               

       ${news.title[0..12]}... 
    </#if>

    4、时间格式化相关

      ${book.date?string('yyyy-MM-dd HH:mm:ss')} 或者${book.date?string('yyyy-MM-dd')}

    5、金钱相关的和数字四舍五入

    ${1?string("000.00")}   001.00
    ${12.1?string("000.00")} 12.10
    ${123.456?string("000.00")}  123.46

    6、数字相关

    ${num?string('0.00')} 
    如果小数点后不足两位,用 0 代替 

    ${num?string('#.##')} 
    如果小数点后多余两位,就只保留两位,否则输出实际值 
    输出为:1239765.46 

    ${num?string(',###.00')} 
    输出为:1,239,765.46 
    整数部分每三位用 , 分割,并且保证小数点后保留两位,不足用 0 代替 

    ${num?string(',###.##')} 
    输出为:1,239,765.46 
    整数部分每三位用 , 分割,并且小数点后多余两位就只保留两位,不足两位就取实际位数,可以不不包含小数点 

    ${num?string('000.00')} 
    输出为:012.70 
    整数部分如果不足三位(000),前面用0补齐,否则取实际的整数位 

    ${num?string('###.00')} 
    等价于 
    ${num?string('#.00')} 
    输出为:12.70

    7、页面如果获取的实体ID为8位的,要进行格式化

    例子:<li class="item"><a href="/product/category-${product.firstLevelId?c}-${product.secondLevelId?c}-${pctlist.id?c}</li>

    如果id为100000的,如果不架上"?c",就会变成格式化的“100,000”

  • 相关阅读:
    转 W P 代码淆混
    Flash网页游戏辅助工具制作简析
    Flash Player安全沙漏规则
    用loader.loadbytes直接load bitmapdata.getpixels产生的bytearray
    游戏及开发人员的认识
    一犯人在执行死刑前三天供出祖传治癌奇方(转)
    AIR教程列表
    养生名言 (春、夏、秋、冬。)
    十天学会单片机和C语言编程
    UI设计规范收藏
  • 原文地址:https://www.cnblogs.com/blogszixin/p/3287057.html
Copyright © 2020-2023  润新知