• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
黄洪波写点东西的地方
博客园    首页    新随笔    联系   管理    订阅  订阅
SpringBoot 使用Thymeleaf解决静态页面跳转问题

参考:springboot配置跳转html页面

1,首先在pom文件中引入模板引擎jar包

 

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2,在application.properties中配置模板引擎

spring.thymeleaf.prefix=classpath:/templates/

3,在templates下建立login.html文件


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>Title</title>
</head>
<body>
<h1>1314314141</h1>
</body>
</html>

4,写controller


package com.example;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by hzm on 2017/4/1.
 */
@Controller
public class HelloController {


    @RequestMapping("/test")
    public String test(){ 
        return "login";
    }
}
5输入网址
http://localhost:8080/test

6页面会出现

1314314141

 

posted on 2018-04-24 21:58  红无酒伤  阅读(2536)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3