2016-11-15 19 views
0

我想了解,如果將我們原有的Struts 1.x Web應用程序遷移到AngularJS + Java RESTful Web Service,將涉及多少工作。 (我知道Struts 1.x與AngularJS不太吻合。)針對Struts1的JSON響應ActionForm

我注意到的第一件事是有很多Struts ActionForm,我想知道是否有更簡單的方法在JSON中獲得響應格式。因此,我們有一流的像這樣的很多:

public class Note extends org.apache.struts.action.ActionForm{ 

//setter and getter... 
} 

我試圖將其轉換爲POJO風格類,然後都需要DAO,幫手,實用工具類這麼多其他的變化也是如此。這是不可避免的嗎?或者先移植到Struts 2然後嘗試採用AngularJS更好?

順便說一句,我得到了日食控制檯這個錯誤,當我試圖讓響應:

org.codehaus.jackson.map.JsonMappingException:未找到類org.apache.struts.action串行.ActionServletWrapper和沒有發現的特性(以避免異常,禁用SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS))(通過引用鏈來創建BeanSerializer:org.kki.dao.oracle.ads.TranscribedNote [ 「用到ServletWrapper」])

更新:

@Path("/note") 
public class NoteRestService { 


@Context 
private HttpServletRequest request; 

@GET 
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) 
public Note [] getNote() { 

    HttpSession session = request.getSession(); 
    User user = (User) session.getAttribute("user"); 
    NoteDAO noteDao = new NoteDAO(null); 
    Note[] note = noteDao.selectNote(user.getUserId()); 

    return note; 
} 
} 

=========

myApp.controller('noteCtrl', ['$scope', 'Note', 

    function ($scope, Note) { 

var vm = this; 
$scope.noteLists = Note.query(function(){ 

    vm.noteList = $scope.noteLists; 
}); 

================

myApp.factory('Note', ['$resource', 
function($resource) { 

    return $resource('http://localhost:8080/angular_demo/rest/note/:id', {id: '@id'}, { 

     get: {method: 'GET', cache: false, isArray: false} 

    }); 

}]); 
+0

你是如何以json格式返回響應的? –

+0

我剛剛編輯了我原來的問題。 – Daniel

+0

下面的答案。 –

回答

0

你有錯誤,因爲Note對象延伸ActionForm。所以你已經繼承了不應該序列化的屬性。只刪除對Note類的依賴關係

public class Note { 

//setter and getter... 
}