Spring Boot DataTable TIMESTAMP range search
Spring Boot DataTable TIMESTAMP range search
Timestamp FIELD - "created" ( Postgresql )
In postgresql I have dates in format
createdDate : "2018-11-01 23:51:33.534" (TIMESTAMP WITHOUT TIME ZONE)
I would like to retrieve all orders for 2018-11-01.
Spring DATA JPA - DATATABLE METHOD
@override
public Predicate toPredicate(Root<Parlamentares> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
Expression<Timestamp> createdDate = root.get("created").as(Timestamp.class);
if (dateBegi != null && dateEnd != null) {
return criteriaBuilder.between(createdDate, dateBegi, dateEnd);
} else if (dateBegi != null) {
return criteriaBuilder.greaterThanOrEqualTo(createdDate, dateBegi);
} else if (dateEnd != null) {
return criteriaBuilder.lessThanOrEqualTo(createdDate, dateEnd);
} else {
return criteriaBuilder.conjunction();
}
}
Everything works fine when i'm using "createdDate DATE column".
dateBegi : "2018-11-01" comes from daterangepick.
How to resolve this problem? Any ideia ?
Replies
This is really more of a Postgres question that a DataTables one, so So might be a better option, however, the way I would do it myself is to use the
extract
function in postgres which will allow you to extract the date part without the time and do a direct comparison against another date.Allan
If you got this problem, you have to reset the value of the "colmunParameter" in the DataTablesInput object.
SOLUTION :
public DataTablesOutput<Parla> listParla(@Valid DataTablesInput input) {
Spring Data Jpa DATATABLES server side, date RANGE filter with TIMESTAMP column POSTGRESQL. /CLOSED