Spring
NoteController
- Path
- pkg21spring/src/main/java/com/javamastery/notes/NoteController.java
- Package
- pkg21spring
- Study order
- 0
- Run
- Read this file. It has no standalone main method.
There is no in-browser runner. This is the file from the curriculum, unchanged.
1package com.javamastery.notes;2 3import org.springframework.web.bind.annotation.*;4 5import java.util.List;6 7@RestController8@RequestMapping("/api/notes")9@CrossOrigin(origins = "*")10public class NoteController {11 private final NoteRepository repo;12 13 public NoteController(NoteRepository repo) {14 this.repo = repo;15 }16 17 @GetMapping18 public List<Note> all() {19 return repo.findAll();20 }21 22 @PostMapping23 public Note create(@RequestBody Note note) {24 return repo.save(note);25 }26 27 @DeleteMapping("/{id}")28 public void delete(@PathVariable Long id) {29 repo.deleteById(id);30 }31}