Created
April 21, 2018 16:38
-
-
Save Gwoks/8007f01d05f52d333fd41579303f9f09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
@RequestMapping("rest") | |
public class RestController { | |
@Autowired | |
RestService restService; | |
@GetMapping("/{id}") | |
public ResponseEntity<RestResult> getById(@PathVariable("id") int id){ | |
RestResult rest = restService.getRestById(id); | |
return new ResponseEntity<RestResult>(rest, HttpStatus.OK); | |
} | |
@GetMapping("/") | |
public ResponseEntity<List<RestResult>> getAll(){ | |
List<RestResult> listRest = restService.getAll(); | |
return new ResponseEntity<List<RestResult>>(listRest, HttpStatus.OK); | |
} | |
@PostMapping("/") | |
public ResponseEntity<RestResult> addRest(@RequestBody Rest rest){ | |
restService.addRest(rest); | |
RestResult rest2 = restService.getRestById(restService.lastestInput()); | |
return new ResponseEntity<RestResult>(rest2,HttpStatus.OK); | |
} | |
@PutMapping("/{id}") | |
public ResponseEntity<RestResult> updateRest(@PathVariable("id") int id, @RequestBody Rest rest){ | |
restService.updateRest(rest,id); | |
RestResult rest2 = restService.getRestById(id); | |
return new ResponseEntity<RestResult>(rest2, HttpStatus.OK); | |
} | |
@DeleteMapping("/{id}") | |
public ResponseEntity<RestResult> deleteRest(@PathVariable("id") int id){ | |
RestResult rest2 = restService.getRestById(id); | |
restService.deleteRestById(id); | |
return new ResponseEntity<RestResult>(rest2,HttpStatus.OK); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mantap