Hallo,
mir ist gurndsätlich klar, wie man RESTful - Services schreibt:
Mir ist nur nicht klar, wie man "getAllUsers" RESTful macht,
entweder so:
oder so wie unten die oben angeführte Methode verwenden und indem ich id=null lasse und dies in dieser Methode unten überprüfe.
Ich wär dankbar für einen Tip in diese Richtung!
Danke!
Poller
mir ist gurndsätlich klar, wie man RESTful - Services schreibt:
Java:
@RequestMapping(value = "{id}", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody User get(@PathVariable
final String id) {
...
}
@RequestMapping(value = "", method = { RequestMethod.POST }, produces = "application/json")
public @ResponseBody User create(final @RequestBody User user) throws BusinessException {
...
}
@RequestMapping(value = "{id}", method = RequestMethod.PUT, consumes = "application/json", produces = "application/json")
public @ResponseBody User update(@PathVariable String id, @RequestBody User user) throws BusinessException {
...
}
Mir ist nur nicht klar, wie man "getAllUsers" RESTful macht,
entweder so:
Java:
@RequestMapping(value = "/getAll", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody List<User> getAll() throws BusinessException {
...
}
oder so wie unten die oben angeführte Methode verwenden und indem ich id=null lasse und dies in dieser Methode unten überprüfe.
Code:
@RequestMapping(value = "{id}", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody User get(@PathVariable
final String id) {
if (id == null) {
// alle User zurückgeben
}
...
}
Ich wär dankbar für einen Tip in diese Richtung!
Danke!
Poller
Zuletzt bearbeitet: