Retrieving a Todo list

We will create a new RestController annotation called TodoController. The code for the retrieve todos method is shown as follows:

    @RestController    public class TodoController {     @Autowired     private TodoService todoService;     @GetMapping("/users/{name}/todos")     public List<Todo> retrieveTodos(@PathVariable String name) {       return todoService.retrieveTodos(name);     }    }

A couple of things to note are as follows:

  • We are autowiring the todo service using the @Autowired annotation
  • We use the @GetMapping annotation to map the Get request for the "/users/{name}/todos" URI to the retrieveTodos method

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.