I have the following scenario:
IretrievethisdatafromaRestAPIwithVraptor.Iwouldliketodisplayonlytwoitemsperpage,butIdonotknowwheretostart.Iimplementedthispagingusingthe 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>