我正在尝试将jpa Pagination与自定义查询一起使用。
如果匹配2个案例,分页正在运作。
案例1:
如果请求不起作用
和
案例2:
如果没有分页不起作用。
我无法弄清楚问题所在。有帮助吗?
提前致谢。
@Repository
public interface SmsLogRepository extends JpaRepository<SmsLog, Long> {
@Query(value = "select * from sms_log s where s.phone_number = (:ph) \n#pageable\n", nativeQuery = true)
Page<SmsLog> findByPhoneNumber(@Param("ph") String phoneNumber, Pageable pageable);
@Query(value = "select * from sms_log s where s.phone_number = (:ph) AND s.message_timestamp between (:fromdate) and (:todate) \n#pageable\n", nativeQuery = true)
Page<SmsLog> findByPhoneNumberAndDate(@Param("ph") String phoneNumber, @Param("fromdate") String fromDate, @Param("todate") String todate, Pageable pageable);
@Query(value = "select * from sms_log s where s.message_timestamp between (:fromdate) and (:todate) \n#pageable\n", nativeQuery = true)
Page<SmsLog> findByDate(@Param("fromdate") String fromDate, @Param("todate") String todate, Pageable pageable);
}
请求:
PageRequest pageRequest = new PageRequest(page, 10, new Sort(new Sort.Order(Sort.Direction.DESC, "message_timestamp")));
return logRepository.findByPhoneNumber(ph, pageRequest);
答案 0 :(得分:1)
花了一些时间后我找到了答案
我错过了计数查询。添加计数查询后,分页工作就像魅力:)
//MAIN ROUTINE
var main = function() {
var doc = app.properties.activeDocument,
fgp = app.findGrepPreferences.properties,
fcgo = app.findChangeGrepOptions.properties,
found, n = 0, text, pTag, xe;
//Exit if no documents open
if ( !doc ) {
alert("You need an open document" );
return;
}
//Setting F/R Grep
app.findGrepPreferences = app.findChangeGrepOptions = null;
app.findGrepPreferences.properties = {
findWhat : "^.+",
}
app.findChangeGrepOptions.properties = {
includeFootnotes:false,
includeHiddenLayers:true,
includeLockedLayersForFind:true,
includeLockedStoriesForFind:true,
includeMasterPages:true,
}
//Adding "p" tag if needed
pTag = doc.xmlTags.itemByName("p");
!pTag.isValid && pTag = doc.xmlTags.add({name:"p"});
//Getting paragraphs occurences
found = doc.findGrep();
n = found.length;
while ( n-- ) {
text = found[n];
xe = text.associatedXMLElements;
//Adding "p" tags with ids if needed
if ( !xe.length || xe[0].markupTag.name!="p") {
doc.xmlElements[0].xmlElements.add( pTag, text ).xmlAttributes.add('id', guid () );
}
}
//Reverting initial F/R settings
app.findGrepPreferences.properties = fgp;
app.findChangeGrepOptions.properties = fcgo;
}
//Returns unique ID
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}
var u;
//Run
app.doScript ( "main()",u,u,UndoModes.ENTIRE_SCRIPT, "The Script" );