功能描述:
服务接收到http请求后,跳转到指定页面。
开发流程:
首先有一个支持该请求的服务类,代码如下:
@Controller
@RequestMapping("/html")
public class HtmlController {
@RequestMapping("/static")
public String staticHtml(String username) {
return "test";
}
}
在/springbootDemo/src/main/resources/templates目录下放一个简单的静态页面
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
这是个静态页面。
</body>
</html>
在浏览器中请求http://localhost:9999/html/static,报错
百度发现,没有配置thymeleaf,还不知道其具体作用,先放上试试
pom.xml中加入依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
application.yml中配置
spring:
mvc:
view:
prefix: /templates/
suffix: .html
重启后重试:
成功!
扫描二维码关注公众号,回复:
5737391 查看本文章