0

我正在尝试向使用 REST 调用以及 JPA/Hibernate/Liquibase 的现有 JAVA Spring/Angular JS Web 应用程序添加功能。我已经遵循了那里的内容,虽然我已经解决了很多错误,但我无法弄清楚最后一个错误是什么。应用程序加载,但没有返回显示的数据。而且我知道数据在数据库中,因为直接 SQL 查询会将其拉回。所以它必须与 Spring/JPA/Hibernate 设置一起使用。我在日志中看到 Angular 控制器调用了我的 PropertiesRestController.java 文件并使用了正确的方法。这反过来又调用了我的 PropertiesDataService.java 文件中的正确方法,该文件在我的 Repository.java 文件中使用了正确的查询/方法。但是当我调试故障点时,代码似乎在 AngularJS 服务中的“data = angular. fromJson(data);"。日志显示每个方法的正确参数,但随后在 PropertiesRestController.java 方法调用中出现错误。. . logging.LoggingAspect - 非法参数 ['Sold','30,'jwt.model.UserContext@xzyABC123',Page request[number: 0, size 20, sort: null]] in . . . . web.rest.controller.PropertiesRestController.findMyProperties() 。. . logging.LoggingAspect - 中的异常。. . web.rest.controller.PropertiesRestController.findMyProperties() with cause = null"。此外,在浏览器的前端使用开发人员工具,我在此页面视图的 AngularJS 服务的“findMyProperties.transformResponse”行中收到“SyntaxError”。java 方法调用与“...... logging.LoggingAspect - 非法参数 ['Sold','30,'jwt.model.UserContext@xzyABC123',Page request[number: 0, size 20, sort: null]] in . . . . web.rest.controller.PropertiesRestController.findMyProperties() . . . logging.LoggingAspect - . . . web.rest.controller.PropertiesRestController.findMyProperties() 中出现异常,原因 = null"。此外,在浏览器的前端,使用开发人员工具,我在此页面视图的 AngularJS 服务的“findMyProperties.transformResponse”行中收到“SyntaxError”。java 方法调用与“...... logging.LoggingAspect - 非法参数 ['Sold','30,'jwt.model.UserContext@xzyABC123',Page request[number: 0, size 20, sort: null]] in . . . . web.rest.controller.PropertiesRestController.findMyProperties() . . . logging.LoggingAspect - . . . web.rest.controller.PropertiesRestController.findMyProperties() 中出现异常,原因 = null"。此外,在浏览器的前端,使用开发人员工具,我在此页面视图的 AngularJS 服务的“findMyProperties.transformResponse”行中收到“SyntaxError”。LoggingAspect - 中的异常。. . web.rest.controller.PropertiesRestController.findMyProperties() with cause = null"。此外,在浏览器的前端使用开发人员工具,我在此页面视图的 AngularJS 服务的“findMyProperties.transformResponse”行中收到“SyntaxError”。LoggingAspect - 中的异常。. . web.rest.controller.PropertiesRestController.findMyProperties() with cause = null"。此外,在浏览器的前端使用开发人员工具,我在此页面视图的 AngularJS 服务的“findMyProperties.transformResponse”行中收到“SyntaxError”。

我对此进行了广泛的网络研究。例如,我添加了“return Optional.ofNullable(myProperty).map(a -> new ResponseEntity<>(a, HttpStatus.OK)).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND) 到 PropertiesRestController.java 方法打电话。在我尝试返回 Page myProperty = myPropertyDataService.getMyProperties(...需要调整的查询我决定至少处理日志文件中报告的空值。我确保@Query 中的 SQL 引用的是实体名称而不是表/SQL 语言(尽管老实说,有些已经使用过我不'在实体定义中看不到,所以我不知道他们从哪里得到那些使用。)

AngularJS 控制器

    $scope.myPropertiesP = [];

    $scope.loadall = function(){
    MyProperties.findMyProperties({propertyStatus:"Pending",listingDate:0,function(result){
    $scope.myPropertiesP = result.content;
});
    $scope.loadall();

AngularJS 服务

    use strict;
    angular.module('propertyApp')
    .factory('MyProperties',function($resource){
      return $resource('rest/api/Properties/my/:propertyStatusName/:propertyListingDate', {}, {
      'findMyProperties': method: 'GET',
         transformResponse: function(data){
           data = angular.fromJson(data);
           return data;
         });
      });
    });

PropertyRestController.java

    @GetMapping(value='/properties/my/{propertyStatusName}/{propertyListingDate}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Page<Properties>> findMyProperties(@PathVariable propertyStatusName, @PathVariable Integer propertyListingDate, @Authenticated User user, Pageable page){
    Page<Properties> myProperty = myPropertyDataService.getMyProperties(propertyStatusName, propertyListingDate,user.getUser(),pageable);
    return Optional.ofNullable(myProperty).map(a -> new ResponseEntity<>(a, HttpStatus.OK)).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
    }

属性数据服务.java

    public Page<Properties> getMyProperties(String propertyStatusName, Integer propertyListingDate, User user, Pageable page){
      if(pageable != null){
        if(propertyListingDate==0)&&(propertyStatusName=='Pending'){
          return PropertyRespository.MyPropertiesP(user.getId(),pageable);
        } else {
          return PropertyRespository.MyPropertiesP(user.getId(), newPageRequest(0,20));
    }
    }

PropertyRepository.java

    public interface PropertyRespository extends JpaRepsotiory(Property,Long>{
        Page<Property> findByNameContaingIgnoreCase(String name, Pageable pageable);
     . . . 

       @Query("select prop from Property prop where prop.propertyOwner = :propertyOwnerId AND (propertyStatus=3 OR prop.propertyStatus=2) ORDER BY prop.propertListingDate DESC")
    Page<Property> myPropertiesP(@Param("propertyOwner") Integer propertyOwnerId, Pageable pageable):


    }



I am supposed to get back JSON strings of database objects to display through AngularJS.
4

0 回答 0