嗨,我是 java 和 JPQL 的新手。在这里,我在 GET 方法的 url 中将 dateTime 作为参数传递。我想要的是我希望用户应该以“yyyy-MM-dd HH:mm:ss”格式传递日期时间。但是现在当我传递日期时间时,它与当前的 dateTime 比较。我希望它应该比较预订按用户通过的日期和时间。这是我的方法和查询。请帮我..
@GET
@Path("/getReservationByUserIdAndTypeAndDateTime/{userid}/{type}/{dateTime}")
public List<Reservation> getReservationByAndUserIdAndTypeAndDateTime(@PathParam("userid") int uid, @PathParam("type") int tid,@PathParam("dateTime")String dateTime) {
CriteriaBuilder builder = em.getCriteriaBuilder();
//Timestamp dateTime = new Timestamp(System.currentTimeMillis());
dateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
//System.out.println("dateTime-"+dateTime);
CriteriaQuery<Reservation> criteria = builder.createQuery(Reservation.class);
Root<Reservation> r = criteria.from(Reservation.class);
TypedQuery<Reservation> query = em.createQuery(
criteria.select(r).where(new Predicate[]{
builder.equal(r.get(Reservation_.usersId), uid),
builder.equal(r.get(Reservation_.reservationsType), tid),
builder.greaterThanOrEqualTo(
builder.concat(r.get(Reservation_.date), r.get(Reservation_.time)), dateTime.toString())}));
return query.getResultList();
}