代码之家  ›  专栏  ›  技术社区  ›  FeliksB

如何将页面与控制器连接

  •  0
  • FeliksB  · 技术社区  · 2 年前

    在这里,我试图用EventController创建一个新页面,并与thymeleaf连接

    @Controller
    public class EventController {
     @RequestMapping(value = "/pereschet", method = RequestMethod.GET)
        public String welcome() {
            return "boom";
        }
    }
    

    这是我的html页面。html

    <html xmlns:th="http://www.thymeleaf.org"
          xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
          xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
          layout:decorator="layout">
    <head>
        <title>Index</title>
    </head>
    <body>
    <h1 >Boombom</h1>
    
    
    </body>
    </html>
    

    当我到达/timetracking/compensative/boom时,它给了我找不到的错误 错误是解析模板“boom”时出错,模板可能不存在,或者任何已配置的模板解析程序都可能无法访问该模板

    我希望看到工作页面,有什么想法?

    0 回复  |  直到 2 年前
        1
  •  0
  •   Sup19    2 年前

    thymeleaf的默认模板目录是src/main/resources/templates。请确保你有砰的一声。html放置在此目录中,因为根据您的问题,没有模板解析程序。请查看我在网上找到的这个链接,了解有关自定义模板解析器的详细信息。 Spring Boot with Thymeleaf