T - Your resource POJO to manage, maybe an entity or DTO classID - Primary resource identifier at webservice level, usually Long or Stringpublic interface RestController<T,ID extends Serializable>
| Modifier and Type | Method and Description |
|---|---|
T |
create(T resource)
Create a new resource
REST webservice published : POST / |
void |
delete()
Delete all resources
REST webservice published : DELETE / Return No Content http status code if the request has been correctly processed |
void |
delete(ID id)
Delete a resource by its identifier
REST webservice published : DELETE /{id} Return No Content http status code if the request has been correctly processed |
Iterable<T> |
findAll()
Find all resources, and return the full collection (plain list not paginated)
REST webservice published : GET /? |
T |
findById(ID id)
Find a resource by its identifier
REST webservice published : GET /{id} |
Iterable<T> |
findByIds(Set<ID> ids)
Find multiple resources by their identifiers
REST webservice published : GET /? |
org.springframework.data.domain.Page<T> |
findPaginated(Integer page,
Integer size,
String direction,
String properties)
Find all resources, and return a paginated and optionaly sorted collection
REST webservice published : GET /search? |
T |
update(ID id,
T resource)
Update an existing resource
REST webservice published : PUT /{id} |
@RequestMapping(method=POST) @ResponseStatus(value=CREATED) @ResponseBody T create(@RequestBody T resource)
resource - The resource to create@RequestMapping(value="{id}",
method=PUT)
@ResponseBody
T update(@PathVariable
ID id,
@RequestBody
T resource)
id - The identifier of the resource to update, usually a Long or String identifier. It is explicitely provided in order to handle cases where the identifier could be changed.resource - The resource to updateNotFoundException@RequestMapping(method=GET,
params="page=no")
@ResponseBody
Iterable<T> findAll()
@RequestMapping(method=GET) @ResponseBody org.springframework.data.domain.Page<T> findPaginated(@RequestParam(value="page",required=false,defaultValue="1") Integer page, @RequestParam(value="size",required=false,defaultValue="10") Integer size, @RequestParam(value="direction",required=false,defaultValue="ASC") String direction, @RequestParam(value="properties",required=false) String properties)
page - Page number starting from 0. default to 0size - Number of resources by pages. default to 10direction - Optional sort direction, could be "asc" or "desc"properties - Ordered list of comma separeted properies used for sorting resulats. At least one property should be provided if direction is specified@RequestMapping(value="{id}",
method=GET)
@ResponseBody
T findById(@PathVariable
ID id)
id - The identifier of the resouce to findNotFoundException@RequestMapping(method=GET,
params="ids[]")
@ResponseBody
Iterable<T> findByIds(@RequestParam(value="ids[]")
Set<ID> ids)
ids - List of ids to retrieve@RequestMapping(method=DELETE) @ResponseStatus(value=NO_CONTENT) void delete()
@RequestMapping(value="{id}",
method=DELETE)
@ResponseStatus(value=NO_CONTENT)
void delete(@PathVariable
ID id)
id - The identifier of the resource to deleteNotFoundExceptionCopyright © 2009–2014. All rights reserved.