java - Getting records with offset and orderBy in activeJDBC -


i duplicate records using:

list<post> postlist = post.findall().limit(long.valueof(request.queryparams("limit"))).offset(long.valueof(request.queryparams("offset"))).orderby("id desc"); 

when remove orderby works fine.

  • first pull: limit 3 offset 0
  • second pull: limit 3 offset 4 //i duplicates on second pull

why so?

update:

table structure:

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 `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: }>); 

request mapping:

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()); 

the returned list<post> postlist empty.

because offset on second pull needs offset + limit.

also, might want paginator built page through results on web pages.

on off-topic, way parse long values parameters vulnerable runtime exceptions if customers start messing url.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -