Spring boot返回html页面

  作者:记性不好的阁主

一、前提准备


导入thymeleaf依赖 (导入后视图路径为[classpath:/templates/*.html])


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>


二、创建页面


在templates目录下新建页面文件




页面内容


<!DOCTYPE html>
<html lang='en' xmlns:th='http://www.thymeleaf.org'>
<head>
<meta charset='UTF-8'>
<title>Title</title>
</head>
<body>
<div></div>
<h1>hello</h1>
</body>
</html>


三、编写controller


controller内容


package com.test.downloadtest.controller;

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

@Controller
public class MainController {
@RequestMapping('/hello')
public String hello(){
return 'hello';
}
}


访问:http://localhost:8080/hello




相关推荐

评论 抢沙发

表情

分类选择