Reputation: 11
I have a spring boot api. My problem is how do I actually create a page in my app?
I created a page in /resources/static/templates/index.html
and when I get to /api/lol
I just see a string saying index and not the page.
How do I do this?
@RequestMapping("/api")
@RestController
public class Controller {
@Autowired
JdbcTemplate jdbcTemplate;
@GetMapping("/lol")
String lol() {
return "index";
}
}
Upvotes: 0
Views: 330
Reputation: 2580
Put your index.html in src/main/resources/static
and then in your controller
@RequestMapping("/api")
@RestController
public class Controller {
@Autowired
JdbcTemplate jdbcTemplate;
@GetMapping("/lol")
String lol() {
return "index.html";
}
}
Upvotes: 0
Reputation: 131496
You annotated your class with @RestController
.
What you want is a MVC Controller, so replace it with @Controller
.
Here is an example of the documentation :
@Controller
public class HelloController {
@GetMapping("/hello")
public String handle(Model model) {
model.addAttribute("message", "Hello World!");
return "index";
}
}
Upvotes: 3