这是我的项目代码片段。在这里,我正在尝试使用Spring Data JPA获取分页数据。分页部分运行正常。但是当searchParameter为NULL时,我只想返回空白页面并创建一个空白页面在我的UI上。
public Page<AccessLog> getDataInRange(long fromTime, long toTime, String searchParameter, Integer start,
Integer length) {
Page<AccessLog> accessPage;
if (searchParameter != null) {
accessPage = accessRepository.findBySystemTimestampBetween(fromTime, toTime,
new PageRequest(start, length));
} else
accessPage = null;
return accessPage;
}
然而,当搜索参数为null时会出现错误
在执行SpringSecurity应用程序时发生异常 java.lang.NullPointerException: null
这是由于将“null”值设置为accessLogPage所导致的。
有什么建议吗?