程序包 org.beetl.core

接口 Format

所有已知实现类:
ContextFormat

public interface Format
格式化函数,用于模版里占位符里的变量格式化后输出
          ${user.birthday,dateFormat='yyyy-MM-dd'}
          ${user.birthday,dateFormat}

     1. dateFormat为格式化函数,通过groupTemplate的registerFormat函数注册,
     2. 等号后面的字符串是需要格式化的样式,如果没有,可以不写
     3. 格式化函数应该支持pattern为null的情况

 public Object format(Object data, String pattern) {
     if (data instanceof Date) {
         SimpleDateFormat sdf = (pattern == null) ? new SimpleDateFormat() : new SimpleDateFormat(pattern);
         return sdf.format(data);
     }
          throw new RuntimeException("Arg Error:Type should be Date");
 }

 
作者:
xiandafu
  • 方法概要

    修饰符和类型
    方法
    说明
    format(Object data, String pattern)
    按照 pattern 指定的模式对 data 对象进行格式化
  • 方法详细资料

    • format

      Object format(Object data, String pattern)
      按照 pattern 指定的模式对 data 对象进行格式化
      参数:
      data - 格式化对象
      pattern - 模式,格式换函数需要考虑到 pattern 为 null 的情况