I m 建立一个简单的RESTFul Service;为了达到这一目的,我需要两项任务:
- Get an instance of my resource (i.e Book) from request parameters, so I can get that instance to be persisted
- Build an XML document from that instance to send the representation to the clients
如今,我马上在我的POJO级做两件事:
public class Book implements Serializable {
private Long id;
public Book(Form form) {
//Initializing attributes
id = Long.parseLong(form.getFirstValue(Book.CODE_ELEMENT));
}
public Element toXml(Document document) {
// Getting an XML Representation of the Book
Element bookElement = document.createElement(BOOK_ELEMENT);
}
我铭记着一项办事处原则,即行为应当发生在数据的地方,但现在,我的公法协会依靠请求和XMLAPIC,并且没有感觉到权利(该类人有持续的说明)。
是否有解决这一问题的标准做法/主人?
EDIT: The libraries i m using are Restlets and Objectify.