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

Convert StringPath to DataPath with custom method

如何使用自定义函数和选定值将 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);
}

使用DateTemplatecreate(Class<T> type, String template, Object one)方法。根据您的 RDBMS,您需要更改以下 template 字符串。我以 Oracle 为例:

DateTemplate.create(LocalDate.class, "TO_DATE({0}, 'DD/MON/YYYY')", from);

我看到您使用的是版本 3 语法。 Querydsl 4 已经发布一段时间了。我会考虑升级。我们已经为一个大型报告项目完成了它,实际上并不太痛苦。在 querydsl 4 中,我相信你会使用 Expressions.dateTemplate.