当前位置: 代码迷 >> Web前端 >> RESTful初探之5(The data layer)
  详细解决方案

RESTful初探之5(The data layer)

热度:492   发布时间:2012-11-23 00:03:43.0
RESTful初探之五(The data layer)
原文:http://www.ibm.com/developerworks/java/tutorials/j-rest/section7.html
This section describes the existing domain objects that make the up data layer that your RESTful service will reuse.
这一章节主要讲数据层已存在的域对象如何在RESTful中重用

Domain objects
As you know from Off to the races: Building a RESTful API, Acme Racing invested in a data layer for a previous project and wants to reuse it for the new Web service.This,of course,makes your job even easier.In a nutshell,the data layer consists of three business objects:Race, Runner, and Result. They are effectively managed by Spring and Hibernate;however,these frameworks are hidden from you;you simply have a JAR file that works nicely(that is,lets you easily create new races,find existing runners,and so on).
之前那篇文章所讲的,Acme Racing 有一个之前有投资过一个数据层级的软件,并希望重用这些数据在新的Web服务中。当然,这使工作更加简单。简单的说,数据层级包含三大业务对象::Race, Runner, and Result. 他们被spring和hibernate有效的管理;但是这些框架对你是隐藏的;你只需一个jar包就能轻松搞定他们。

The business objects support a series of finder methods that make obtaining race and runner instances quite easy. Objects can be persisted,updated,and removed from the underlying database via save(), update(), and remove() methods, respectively.
业务对象提供了很多查询方法,使获得race和runner实例非常容易。对象可以被独立地保存,修改和删除通过save(), update(), and remove()。

For example,a Race object supports a series of finder methods and facilitates manipulating persisted data nicely.The Race object's API is straightforward,as shown in Listing10:                 

Collection<Race> findAll();
Race findById(long id);
Race findByName(String name);
void create(Race race);
void update(Race race);
void remove(Race race);

A Race instance has a number of properties,as shown in Listing11:
private long id;
private String name;
private Date date;
private double distance;
private Set<Runner> participants;
private Set<Result> results;
private String description;

All of Race's properties are available via getters and setters. What's more, collections of items (such as participants and results) support adding individual items. Therefore, the Race object has an addParticipant() method, shown in Listing 12:
public void addParticipant(final Runner participant) ;




  相关解决方案