Skip to content

Instantly share code, notes, and snippets.

@Gwoks
Created April 21, 2018 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gwoks/8007f01d05f52d333fd41579303f9f09 to your computer and use it in GitHub Desktop.
Save Gwoks/8007f01d05f52d333fd41579303f9f09 to your computer and use it in GitHub Desktop.
@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);
}
}
@Edijun
Copy link

Edijun commented Jun 8, 2018

Mantap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment