示例#1
0
 @RequestMapping(value = "/book", method = RequestMethod.POST)
 public ResponseEntity create(@RequestBody Book book) {
   for (Book a : books) {
     if (a.getId() == book.getId())
       return new ResponseEntity<String>(null, new HttpHeaders(), HttpStatus.FOUND);
   }
   books.add(book);
   return new ResponseEntity<Book>(book, new HttpHeaders(), HttpStatus.OK);
 }
示例#2
0
 @RequestMapping(value = "/book/{id}", method = RequestMethod.GET)
 public ResponseEntity show(@PathVariable("id") int id) {
   for (Book b : this.books) {
     if (b.getId() == id) {
       return new ResponseEntity<Book>(b, new HttpHeaders(), HttpStatus.OK);
     }
   }
   return new ResponseEntity<String>(null, new HttpHeaders(), HttpStatus.NOT_FOUND);
 }
示例#3
0
 @RequestMapping(value = "/book/{id}", method = RequestMethod.DELETE)
 public ResponseEntity remove(@PathVariable("id") int id) {
   for (Book b : this.books) {
     if (b.getId() == id) {
       this.books.remove(b);
       return new ResponseEntity<String>(null, new HttpHeaders(), HttpStatus.NO_CONTENT);
     }
   }
   return new ResponseEntity<String>(null, new HttpHeaders(), HttpStatus.NOT_FOUND);
 }
示例#4
0
 @RequestMapping(value = "/book/{id}", method = RequestMethod.PUT)
 public ResponseEntity update(@RequestBody Book book) {
   for (Book b : this.books) {
     if (b.getId() == book.getId()) {
       b.setTitlu(book.getTitlu());
       b.setEditura(book.getEditura());
       return new ResponseEntity<Book>(b, new HttpHeaders(), HttpStatus.OK);
     }
   }
   return new ResponseEntity<String>(null, new HttpHeaders(), HttpStatus.NOT_FOUND);
 }