mardi 19 mai 2015
REST- Services GET/PUT/POST/DELETE
Posted on 07:27 by verona
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 Code:
-
-
@RequestMapping(value = "{id}", method = RequestMethod.GET, produces = "application/json")
-
public @ResponseBody User get(@PathVariable
-
...
-
}
-
-
@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 Code:
-
-
@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
}
...
}
Danke!
Poller
REST- Services GET/PUT/POST/DELETE
Categories: REST- Services GET/PUT/POST/DELETE
Inscription à :
Publier les commentaires (Atom)
0 commentaires:
Enregistrer un commentaire