是的 jersey 是允许路由配置的 RESTful API(仅带有注释)
例子 :
package com.frimastudio.webservice.controller.route;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.joda.time.DateTime;
import com.frimastudio.webservice.controller.representation.Time;
@Path("/time")
@Produces(MediaType.APPLICATION_JSON)
public class TimeResource
{
public TimeResource()
{
}
@GET
public Time getServerDate()
{
return new Time(new DateTime());
}
}
时间是杰克逊的代表:
package com.frimastudio.webservice.controller.representation;
import org.hibernate.validator.constraints.NotEmpty;
import org.joda.time.DateTime;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Time
{
@NotEmpty
@JsonProperty
private String date;
public Time()
{
// Jackson deserialization
}
public Time(String date)
{
super();
this.date = date;
}
public Time(DateTime date)
{
super();
this.date = date.toString();
}
}