我使用以下方法获得重复记录:
List<Post> postList = Post.findAll().limit(Long.valueOf(request.queryParams("limit"))).offset(Long.valueOf(request.queryParams("offset"))).orderBy("id desc");
当我删除 orderBy 它工作正常。
- 第一次拉: limit is 3 offset is 0
- 第二次拉动: limit is 3 offset is 4
//I get duplicates on second pull
为什么会这样?
更新:
表结构:
CREATE TABLE `post` (
`id` mediumint(15) NOT NULL AUTO_INCREMENT,
`title` text,
`details` text,
`created_at` text,
`username` varchar(45) DEFAULT NULL,
`userImage` text,
`url` varchar(1000) DEFAULT NULL,
`article_id` text NOT NULL,
`postImageUrl` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=243 DEFAULT CHARSET=utf8;
INSERT INTO `lt9vgms366ueidoa`.`post`
(`id`,
`title`,
`details`,
`created_at`,
`username`,
`userImage`,
`url`,
`article_id`,
`postImageUrl`)
VALUES
(<{id: }>,
<{title: "Test"}>,
<{details: "Test"}>,
<{created_at: }>,
<{username: "Test"}>,
<{userImage: }>,
<{url: "Test"}>,
<{article_id: "121"}>,
<{postImageUrl: }>);
请求映射:
get("/get_data_on_scrollEnd", (Request request, Response response) -> {
System.out.println("ON SCROLL END -- LIMIT: "+ request.queryParams("limit") + " " + "OFFSET: "+ request.queryParams("offset"));
List<Post> postList = Post.findAll().limit(Long.valueOf(request.queryParams("limit"))).offset(Long.valueOf(request.queryParams("offset")));
System.out.println("///////////////////////");
log.info("PAGINATION: " + postList);
System.out.println("///////////////////////");
return postList;
}, new JsonTransformer());
返回List<Post> postList
的是空的。