【问题标题】:angularjs ( call rest in Hibernate )angularjs ( 在 Hibernate 中调用 rest )
【发布时间】:2018-09-14 01:52:09
【问题描述】:

作为标题,我的问题以及如何在 angularjs 的帮助下调用服务。 我的项目是用 Dao 和 Dao Impl 构建的,rest 和 hibernate,看我一步步构建的代码。 我的问题在于控制器和不保留数据的 html 页面。 你能查看我的代码吗?看看我错在哪里?如果我错了,我可以纠正吗?

方法getSkill:

 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;
   }

休息:

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

控制器:

(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 .... "> //in here what should I put in order to recall the services rest ??? have you seen my method and the 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>

【问题讨论】:

    标签: java html angularjs rest


    【解决方案1】:

    我希望这会有所帮助。

    控制器

    (function () {
    var app = angular.module("myApp");
    app.controller("read3", function($scope, $http) {
       $http.get('http://localhost:8900/HibernateRestDao/getSkill').then(
             function success(response) {
                $scope.skillList = response.data;
                //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 skillList"> //everytime controller is loaded, this variable will refresh with data
             <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-07
      相关资源
      最近更新 更多