java - how to orderBy string date? CriteriaBuilder -
how can orderby
string date correctly(in date format) using criteria builder? because stored date in model string.
my model:
@column(name = "date_time")
private string datetime;
when try query it.
criteriabuilder cb = jpa.em().getcriteriabuilder(); criteriaquery<t> cq = cb.createquery(pickup.class); root<t> root = cq.from(pickup.class); criteriaquery<t> = cq.select(root); cq.orderby(cb.desc(root.get("datetime")));
i got wrong order, how can make string date date format orderby it? i'm new it, can me? in advance.
datetimeformatter datetimeformatter = datetimeformat.forpattern("yourpattern"); criteriabuilder cb = jpa.em().getcriteriabuilder(); criteriaquery<t> cq = cb.createquery(pickup.class); root<t> root = cq.from(pickup.class); criteriaquery<t> = cq.select(root); cq.orderby(cb.desc(datetimeformatter.parsedatetime(root.get("datetime"))));
you can convert datetimestring datetime datetimeformatter.
Comments
Post a Comment