2016-05-16 35 views
0

我正在構建類似儲物櫃管理系統的東西,並且儲物櫃有更新歷史記錄。我想用Ajax將這個歷史記錄的列表返回到列表中的X條目。無論何時我返回List<LockerHistoryEntity>Iterable<LockerHistoryEntity>,都會返回對象的數量,但所有對象都是空的。彈出Ajax列表返回但對象爲空

Example of the problem

Ajax調用(在這種情況下,呼籲與getHistory(100)):

function getHistory(limit) { 
    var data = {}; 
    data["limit"] = limit; 

    $.ajax({ 
     type: "POST", 
     contentType: "application/json", 
     url: "/gethistory", 
     data: JSON.stringify(data), 
     dataType: 'json', 
     timeout: 100000, 
     success : function(data) { 
      fillTable(data); 
      console.log(data); 
      console.log(data.result); 
     }, 
     error : function(e) { 
      //error 
     } 
    }); 
} 

@RestController

@JsonView(Views.Public.class) 
    @RequestMapping(value = "/gethistory", method = RequestMethod.POST, produces="application/json") 
    @ResponseBody 
    public Iterable<LockerHistoryEntity> getHistory(@RequestBody HistoryLimit limit) { 
     Iterable<LockerHistoryEntity> lockerHistory; 

     if (limit.getLimit() >= 0) { 
      lockerHistory = history.findAllLimit(limit.getLimit()); 
     } else { 
      lockerHistory = history.findAll(); 
     } 

     return lockerHistory; 
    } 

當使用一個for循環打印出lockerHistory的數據是所有正確顯示。

不幸的是,我找不到任何關於這個確切問題的話題,因此這篇文章。

+0

您是否嘗試將對象轉換爲JSON?我在這裏找到一些有用的鏈接http://www.baeldung.com/spring-httpmessageconverter-rest希望它可以幫助 –

+1

謝謝,確實解決了它。忘了解析爲JSON。 – Randyr

回答