百里香叶:调用端点后无法显示视图

时间:2019-08-09 14:58:52

标签: spring rest web-services web thymeleaf

我试图调用REST端点,然后显示ThymeLeaf模板:

终点:

@GetMapping("/devices")
public String getDeviceDetailU(Model model) {
  List<FinalDevice> devices = deviceService.getAll();
  model.addAttribute("devices", devices);
  return "deviceList";  
}

对于端点,我尝试返回/deviceList、/deviceList.html、deviceList.html。

每当我导航到端点时,我都会得到返回的字符串。

这是模板:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org"
      xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
    <body>
Hello World!
    </body>
</html>

虽然我了解到这一点,但它不会显示列表,我只想转发到模板。

如果我转到localhost:8080 / deviceType,则显示该模板。对我来说,这表明这不是安全性或配置问题。

有什么想法吗?

这一切都应该按照tutorial.

进行

1 个答案:

答案 0 :(得分:1)

您可能拥有@RestController而不是@Controller

如果要渲染模板,则需要使用@Controller@RestController意味着所有@Mappings都简单地序列化返回值并将其输出为json或xml(这就是为什么看到字符串deviceList而不是模板的原因)。

相关问题