使用自定义方法将StringPath转换为DataPath

时间:2015-09-01 14:04:33

标签: querydsl

如何使用自定义函数和选定值将StringPath转换为DatePath?

我想在自定义谓词中使用数据库中的值,如下所示

public static Predicate hasBirthdateGreaterOrEqual(String from) {

    //how to convert this to String and pass to PeselParser(String value)
    StringPath peselValue = QEmployee.employee.employment.person.peselValue;

    LocalDate employeeDate = new PeselParser(peselValue).getDate();

    DateExpression<LocalDate> expression = DateTemplate.create(LocalDate.class, from);
    return expression.goe(employeeDate);
}

1 个答案:

答案 0 :(得分:3)

使用DateTemplate的{​​{1}}方法。根据您的RDBMS,您将要更改以下create(Class<T> type, String template, Object one)字符串。我以Oracle为例:

template

我看到你正在使用版本3语法。 Querydsl 4已经出现了一段时间了。我考虑升级。我们已经为一个大型报告项目做了它,实际上并没有太痛苦。在querydsl 4中,我相信你会使用DateTemplate.create(LocalDate.class, "TO_DATE({0}, 'DD/MON/YYYY')", from);

相关问题