springboot中使用thymeleaf进行HTML页面跳转时出现500错误!!!!!

springboot中使用thymeleaf进行HTML页面跳转时出现500错误!!!!!

第一次写的时候,总是500错误,看了网上好多解决方案,都不管用,终于解决了。我的问题主要是在pom.xml文件中少导入一个下面的依赖!!!!,导入好多依赖都不对,下面这个终于对了(感到),希望对大家有帮助!!

<dependency>
            <groupId>net.sourceforge.nekohtml</groupId>
            <artifactId>nekohtml</artifactId>
            <version>1.9.22</version>
    </dependency>


–下面写一下主要步骤–
1、在yml文件中,写入thymeleaf属性

spring: 
    thymeleaf:
        mode: HTML
        encoding: utf-8
        cache: false
        prefix: classpath:/templates/
        suffix: .html


这一步大家应该都不会出错

2、在pom.xml文件进行配置(我的问题根源)

<dependency>
            <groupId>net.sourceforge.nekohtml</groupId>
            <artifactId>nekohtml</artifactId>
            <version>1.9.22</version>
    </dependency>


    <!--我的问题就在于没有加下面这个依赖!!!!!!!!!!!!!!-->

    <dependency>
            <groupId>net.sourceforge.nekohtml</groupId>
            <artifactId>nekohtml</artifactId>
            <version>1.9.22</version>
    </dependency>


3、在resources下面的templates下新建一个test.html文件

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!--在默认条件下只加这一行-->
    <h1>welcome to ...</h1>
</body>
</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
在这里插入图片描述
好,到此结束了。
希望大家不要遇到我的问题

 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值