我需要找到用户所提供日期之间的表格记录。我正试着为此编写说明书,但它出现了编译时错误,如下所示:
The method between(Expression<? extends Y>, Expression<? extends Y>, Expression<? extends Y>)
in the type CriteriaBuilder
is not applicable for the arguments (Expression<Date>, Object, Object)
我已经在各个论坛上尝试搜索,但是无法找到如何解决这个问题的方法,可能是我做错了什么。请在这方面帮助我。
规范类
public class ScheduleClassSpecification implements Specification<ScheduleClassInformation> {
private SearchCriteria criteria;
@Override
public Predicate toPredicate(Root<ScheduleClassInformation> root,
CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
Expression<String> expression;
Predicate predicate =null;
if((criteria.getKey().equalsIgnoreCase("student"))){
expression = root.join("course").join("student").get("student");
predicate = criteriaBuilder.equal(expression, criteria.getValue());
}else if(criteria.getKey().equalsIgnoreCase("startDate") || criteria.getKey().equalsIgnoreCase("endDate")){
predicate = criteriaBuilder.between
(root.<Date>get(criteria.getKey()).as(java.util.Date.class),
criteria.getValue(),
criteria.getValue()); // Compile Time Error on this line
}
return predicate;
}
条件类
public class SearchCriteria {
private String key;
private String operation;
private Object value;}
提取存储库中记录的服务
if(!Utility.isNull(Id)){
idSpec = new ScheduleClassSpecification(new SearchCriteria("Student",":",Id));
}
Page<SCOutput> listreturn = scRepo.findAll(Specification.where(idSpec), SCOutput.class,new PageRequest(0, 100));
criteria.getValue()
强制转换为Date
吗? - Sukhpal Singh