DirectiveUtil.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:appleframework 作者:
/**
 * 获取Date类型的参数值
 * 
 * @return 参数值
 */
public static Date getDateParameter(String name, Map<String, TemplateModel> params) throws TemplateModelException {
    TemplateModel templateModel = params.get(name);
    if (templateModel == null) {
        return null;
    }
    if (templateModel instanceof TemplateScalarModel) {
        String value = ((TemplateScalarModel) templateModel).getAsString();
        if (StringUtils.isEmpty(value)) {
            return null;
        }
        try {
            String[] pattern = new String[]{"yyyy-MM","yyyyMM","yyyy/MM", "yyyyMMdd","yyyy-MM-dd","yyyy/MM/dd", "yyyyMMddHHmmss", "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss"};
            return DateUtils.parseDate(value, pattern);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    } else if ((templateModel instanceof TemplateDateModel)) {
        return ((TemplateDateModel) templateModel).getAsDate();
    } else {
        throw new TemplateModelException("The \"" + name + "\" parameter " + "must be a date.");
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号