Home > Net >  DataTables server-side pagination with jdbctemplate
DataTables server-side pagination with jdbctemplate

Time:07-06

I am new to Spring boot and making a project without implementing JPA(instead i used JdbcTemplate) but Now I am facing problem in LIMIT and OFFSET to fetch required amount of rows to display on each page of Datatable.Can Anyone please tell me the solution.

CodePudding user response:

You need to add LIMIT and OFFSET in your query and set the args and their types as follow:

public List<YourType> getPagedResults(int offset, int limit) {
   // Add LIMIT and OFFSET in the query
   String sql = "SELECT * FROM my_table LIMIT ? OFFSET ?";  
   // Set the args
   Object[] args = new Object[]{offset, limit};
   // and arg types
   int[] types = new int[]{INTEGER, INTEGER};
   // Execute the paginated query
   return jdbcTemplate.query(sql, args, types, rowMapper);
}
  • Related