0
I have the following scenario:
I recover this data from a Rest API with Vraptor. I would like to display only two items per page, but I don’t know where to start. I implemented this pagination using the ui-bootstrap.
How do I make a dynamic query and display only two items per page?
Back-end:
Controller:
@Get
@Path("/colaboradores")
public void listarTodos() {
result.use(Results.json())
.withoutRoot()
.from(colaboradorDAO.listarColaboradores())
.serialize();
}
DAO:
@SuppressWarnings("unchecked")
public List<Colaborador> listarColaboradores() {
List<Colaborador> lista = new ArrayList<>();
Session sessao = HibernateUtil.getSessionFactory().openSession();
Transaction transacao = null;
try {
transacao = sessao.beginTransaction();
Query consulta = sessao.getNamedQuery("Colaborador.listar");
lista = consulta.list();
transacao.commit();
} catch (RuntimeException ex) {
ex.printStackTrace();
throw ex;
} finally {
sessao.close();
}
return lista;
}
Front-end:
Controller:
angular.module("oraculo").controller("colaboradorController", function($scope, $routeParams, $location, colaboradorAPI){
$scope.tamanhoMaximo = 6;
$scope.totalItems = 175;
$scope.currentPage = 1;
...//Código Omitido
Page:
...//Trecho omitido
</table>
<pagination total-items="totalItems" ng-model="currentPage" max-size="tamanhoMaximo" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>
<pre>Page: {{currentPage}} / {{numPages}}</pre>
i would pass these parameters either by GET or by POST?
– DiegoAugusto
You can pass via GET
– Emir Marques
Got it, I’m just passing the currentPage, it’s almost working but it’s still not paying the right way. What I spend on this
MaxResults
?– DiegoAugusto
And when I jump to the next page it repeats the last record of the previous page, in addition to the registration with code = 1 not appear in the query
– DiegoAugusto
Maxresults vc defines until which page will be returned. Imagine the following situation. You have 100 records in the database. Passing Firstresult=10 and Maxresults=20 Hibernate will return only the records between this track, that is, records between 10 and 20, understood?
– Emir Marques
He doesn’t repeat the last record, he switches to the next
– Emir Marques
Got it, how I don’t show it on the next page?
– DiegoAugusto
On the return of your service you arrow $Scope. <object_name> = <return of service>
– Emir Marques