I'm trying to filter a table called Measure through its field customerId. This is what the beginning of the controller for the path looks like:
@RequestMapping(method = GET, path = "/nodes/{id}/ports/{portid}/measures")
@ResponseBody
public ResponseEntity<?> getPortMeasures(@PathVariable long id, @PathVariable long portid,
@RequestParam Optional<Long> from,
@RequestParam Optional<String> order,
@RequestParam Optional<String> countername,
@RequestParam Optional<Long> to) {
Followed by the method that calls the query undernath
if (order.isPresent() && order.get().equals("asc")) {
return ResponseRestBuilder.createSuccessResponse(
measureRepository.
searchAsc
(networkElementList.get(0).ip, portList.get(0).rack, portList.get(0).frame, portList.get(0).slot,
portList.get(0).portSerial, countername.get(), from.orElse(0L), to.orElse(99999999999999999L)));
}
else{
return ResponseRestBuilder.createSuccessResponse(
measureRepository.
searchDesc
(networkElementList.get(0).ip, portList.get(0).rack, portList.get(0).frame, portList.get(0).slot,
portList.get(0).portSerial, countername.get(), from.orElse(0L), to.orElse(99999999999999999L)));
}
This is what the queries look like:
@Query("SELECT mes FROM Measure mes WHERE " +
"mes.nodeIp = (:nodeIp) AND " +
"mes.rack = (:rack) AND " +
"mes.frame = (:frame) AND " +
"mes.slot = (:slot) AND " +
"mes.portSerial = (:portSerial) AND " +
"lower(mes.counterName) LIKE concat('%', lower(:countername), '%') AND"+
"mes.timestamp > (:timestamp1) AND " +
"mes.timestamp < (:timestamp2) "+
"ORDER BY mes.timestamp DESC")
List<Measure> searchDesc(@Param("nodeIp") String nodeIp, @Param("rack") String rack, @Param("frame") String frame,
@Param("slot") String slot, @Param("portSerial") String portSerial, @Param("countername") String countername,
@Param("timestamp1") Long timestamp1, @Param("timestamp2") Long timestamp2);
@Query("SELECT mes FROM Measure mes WHERE " +
"mes.nodeIp = :nodeIp AND " +
"mes.rack = :rack AND " +
"mes.frame = :frame AND " +
"mes.slot = :slot AND " +
"mes.portSerial = :portSerial AND " +
"lower(mes.counterName) LIKE concat('%', lower(:countername), '%') AND " +
"mes.timestamp > :timestamp1 AND " +
"mes.timestamp < :timestamp2 "+
"ORDER BY mes.timestamp ASC")
List<Measure> searchAsc(@Param("nodeIp") String nodeIp, @Param("rack") String rack, @Param("frame") String frame,
@Param("slot") String slot, @Param("portSerial") String portSerial, @Param("countername") String countername,
@Param("timestamp1") Long timestamp1, @Param("timestamp2") Long timestamp2);
It's not filtering anything because the controller replies with 0 rows. I'm 100% confident there are actual rows because I've checked with other rest calls. What am I doing wrong?
问题很可能与timestamp字段有关,从代码中似乎您传递了很长时间,但实际上它正在等待timestamp文字,jpa中的timestamp文字格式为{ts '2009-11-05 12-45-52.325'}
...只是检查一下,尝试从查询中删除时间戳,然后再次放入并手动提供文字...如果{ts '2009-11-05 12-45-52.325'}
,则需要找到一种方法来解析传递的long到相应的文字
The problem with it was the field portList.get(0).rack being "null". Appartently this made the whole query not work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.