Files
spring-boot-rest/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/controller/PersonController.java
vatsalgosar f43db12fcb BAEL-2728 | vatsalgosar@gmail.com
- Adding spring-boot-configuration project to spring-boot-bootstrap module
2019-07-16 01:55:08 +05:30

40 lines
979 B
Java

package com.baeldung.controller;
import com.baeldung.domain.Person;
import com.baeldung.exception.PersonNotFoundException;
import com.baeldung.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/persons")
public class PersonController {
@Autowired
PersonService personService;
@GetMapping
public List<Person> getPersons() {
return personService.getPersons();
}
@PostMapping
public void addPerson(@RequestBody Person person) {
personService.add(person);
}
@GetMapping("/{id}")
public Person getPersonById(@PathVariable(required = true) long id) throws PersonNotFoundException {
return personService.getPersonById(id);
}
@DeleteMapping("/{id}")
public void removePerson(@PathVariable(required = true) long id) {
personService.delete(id);
}
}