程序包 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
按照pattern指定的模式对data对象进行格式化- 参数:
data- 格式化对象pattern- 模式,格式换函数需要考虑到 pattern 为 null 的情况
-