Java 规范中如何连接两个结果。
我正在使用 Java 规范,其中使用两个表 Student 和 StudentResult。
当我查询我的 API 时
http://localhost:8080/student?query=grade:5,lastRollResult%40SUCCESS%23FAILURE
在这种情况下,我可以从
Join results = root.join("lastRollResult", JoinType.INNER);
获取数据,这是从 StudentResult 表中获取的。
同样,当我将空值作为lastRollResult传递时,我从
return root.get("lastRunId");
获取数据,这是从学生表中获取的,因为没有结果,所以结果列为空。
我的问题是,当我传递任何枚举(如成功或失败)时如何连接这两个结果。
@Override
protected Expression<String> getPath(SearchCriteria criteria, Root<Student> root) {
if (criteria.getKey().equals("lastRollResult")) { // codition check null. avoid join. [tests suit]
if (!"null".equals(criteria.getValue())) {
Join results = root.join("lastRollResult", JoinType.INNER);
return results.get("result");
} else {
return root.get("lastRunId");
}
}
return root.get(criteria.getKey());
}
修改:将Join results改为Join
protected Expression<String> getPath(SearchCriteria criteria, Root<Student> root) {
if (criteria.getKey().equals("lastRollResult”)) { // codition check null. avoid join. [tests suit]
if (!"null".equals(criteria.getValue())) {
Join<Student,StudentResult> results = root.join("lastRollResult", JoinType.INNER);
return results.get("result");
} else {
return root.get("lastRunId");
}
}
return root.get(criteria.getKey());
}