我有一个 Spring Boot api。我的问题是如何在我的应用程序中实际创建页面?
我在/resources/static/templates/index.html 中创建了一个页面
当我到达 /api/lol
时,我只看到一个表示索引的字符串,而不是页面。
我该怎么做?
@RequestMapping("/api")
@RestController
public class Controller {
@Autowired
JdbcTemplate jdbcTemplate;
@GetMapping("/lol")
String lol() {
return "index";
}
}
最佳答案
您使用 @RestController
注释了您的类。
您想要的是 MVC Controller ,因此将其替换为 @Controller
。
这是 documentation 的示例:
@Controller
public class HelloController {
@GetMapping("/hello")
public String handle(Model model) {
model.addAttribute("message", "Hello World!");
return "index";
}
}
关于java - 将页面添加到 Spring Boot 应用程序(极其基本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51212092/