I’m trying to make the simplest application, but for some reason the page doesn’t see my GetMapping(“/”)
MainController
package com.example.ToDoList.controller;
import com.example.ToDoList.service.NoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class MainController {
@Autowired
NoteService noteService;
public MainController(NoteService noteService) {
this.noteService = noteService;
}
@GetMapping("/")
public String main(Model model){
model.addAttribute("notes", noteService.getAll());
return "main";
}
}
main.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Main</title>
</head>
<body>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">id</th>
<th scope="col">note</th>
</tr>
</thead>
<tbody>
<tr th:each="note: ${notes}">
<th th:text="${note.getId()}" scope="row"></th>
<td th:text="${note.getNote()}"></td>
</tr>
</tbody>
</table>
</body>
</html>
ToDoListApplication
package com.example.ToDoList;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan("com.example.ToDoList")
public class ToDoListApplication {
public static void main(String[] args) {
SpringApplication.run(ToDoListApplication.class, args);
}
}
project structure
I don’t understand where I went wrong, maybe with my main.html something is wrong, but the GetMapping request must be correct
New contributor
OGKAZA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.