Hibernate - angualr js - rest - problem call rest in angularjs


#1

Goodmorning everyone,

My problem is to call the services through hibernate with angular js.
this is my code:

getAllSkill:

public List<Skill> getAllSkill() {
      List<Skill> listaSkill = new ArrayList<Skill>();
      HibernateConnection connectionHibernate = new HibernateConnection();
      // EntityManager Gestisce connessioni e transazioni,
      EntityManager manager = connectionHibernate.getEntityManagerFactory();

      // serve per gestire le operazioni di inserimento
      EntityTransaction entityTransaction = null;

      try {
         entityTransaction = manager.getTransaction(); // restituisci la transizione delle classi pojo
         entityTransaction.begin(); // inizia la transizione query
         listaSkill = manager.createQuery("select q from Skill q", Skill.class).getResultList(); // READ SKILL
         entityTransaction.commit(); // committa
      } catch (Exception e) {
         System.out.println("Errore -> " + e.getMessage());
         if (entityTransaction != null) {
            entityTransaction.rollback();
         }
      } finally {
         try {
            if (manager != null) {
               manager.close(); // chiudi
            }
         } catch (Exception e2) {
            e2.printStackTrace();
         }
      }
      return listaSkill;
   }

rest:

// READ ALL SKILL
   @GET
   @Path("/getSkill")
   @Produces(MediaType.APPLICATION_JSON) // trasforma in json
   public Response getListSkill() {

      // Chiamo la Factory
      ISkillDao iDao = new SkillDaoImpl();

      List<Skill> result = iDao.getAllSkill();

      return Response.ok().entity(result).build();
   }

controller angular js:

(function () {
var app = angular.module("myApp");
app.controller("read3", function($scope, $http) {
   $http.get('http://localhost:8900/HibernateRestDao/getSkill').then(
         function success(response) {
            alert(response.data);
         }, function myError(response) {
            consol.log("errore");
         });
});
})();

html:

<div>
   <table>
      <tr>
         <th>Id Skill</th>
         <th>Nome</th>
         <th>Cognome</th>
         <th>Update</th>
         <th>Delete</th>
      </tr>
      <tr ng-repeat="x in .... "> //qui dentro che cosa ci devo mettere per richiamare i servizi rest??? ---> avete visto il mio metodo e il rest?
         <td>{{x.idSkill }}</td>
         <td>{{x.nome }}</td>
         <td>{{x.cognome }}</td>
         <td><a href="#!update3/{{x.idCandidato }}" class="btn btn-info">Update
               Candidato</a></td>
         <td><a href="#!delete3/{{x.idCandidato }}" class="btn btn-info">Delete
               Candidato</a></td>
      </tr>
   </table>
</div>

Can you help me to get data out of the HTML page ???


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.