-
Notifications
You must be signed in to change notification settings - Fork 0
/
PersonRestController.java
45 lines (35 loc) · 1.19 KB
/
PersonRestController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.example.demo.controller;
import com.example.demo.model.Person;
import com.example.demo.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("api/people")
public class PersonRestController {
private final PersonService personService;
@Autowired
public PersonRestController(PersonService personService) {
this.personService = personService;
}
@GetMapping
public List<Person> getPeople(){
return personService.findAll();
}
@GetMapping ("{personId}")
public Person getPerson(@PathVariable("personId") Long personId){
return personService.findById(personId);
}
@PostMapping
public void addPerson (@RequestBody Person person) {
personService.save(person);
}
@PutMapping ("{personId}")
public void updatePerson (@RequestBody Person person, @PathVariable Long personId) {
personService.update(personId, person);
}
@DeleteMapping ("{personId}")
public void deletePerson (@PathVariable Long personId) {
personService.deleteById(personId);
}
}