springboot中使用thymeleaf进行HTML页面跳转时出现500错误!!!!! |
您所在的位置:网站首页 › springboot项目访问html页面 › springboot中使用thymeleaf进行HTML页面跳转时出现500错误!!!!! |
第一次写的时候,总是500错误,看了网上好多解决方案,都不管用,终于解决了。我的问题主要是在pom.xml文件中少导入一个下面的依赖!!!!,导入好多依赖都不对,下面这个终于对了(感到),希望对大家有帮助!! net.sourceforge.nekohtml nekohtml 1.9.22–下面写一下主要步骤– 1、在yml文件中,写入thymeleaf属性 spring: thymeleaf: mode: HTML encoding: utf-8 cache: false prefix: classpath:/templates/ suffix: .html这一步大家应该都不会出错 2、在pom.xml文件进行配置(我的问题根源) org.springframework.boot spring-boot-starter-thymeleaf net.sourceforge.nekohtml nekohtml 1.9.223、在resources下面的templates下新建一个test.html文件 4、建一个controller类 这里需要注意一点:/在templates下面的页面只能通过Controller来跳转,不能使用@RestController注解 package com.qsf.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; //在templates下面的页面只能通过Controller来跳转,不能使用@RestController注解 @Controller public class IndexController { @RequestMapping("/index") public String index(){ return "test";//跳转到这个test.html页面 } }5、运行启动类 在浏览器中输入http://localhost:8080/index |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |