springboot controller templates html

首先声明:

  @Controller注解的类必须要在启动类的子集目录下,否则无法扫描

本文要求:

  通过controller层跳转页面到html页面(本篇用到thymeleaf模板)

项目结构展示:

第一步:pom.xml

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

第二步:application.properties(最后两条可加可不加)

server.port=9999
server.servlet.context-path=/
server.tomcat.uri-encoding=UTF-8
spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html
#spring.thymeleaf.cache=false

第三步:m3.html(随便写写)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
video{
100%;
height: 100%;
}
</style>
</head>
<body>
<h1>helloword</h1>
<video src="videos/working-man.mp4" muted="" autoplay="" loop=""></video>
</body>
</html>

第四步:controller

@Controller
public class HomePage {
//, produces = "application/json;charset=utf-8"
@RequestMapping(value = "/index")
public String index(){
return "m3";
}
}

实现图片:(谷歌地址栏录入:localhost:9999/index

 

总结:

花非花,梦非梦,蝶非蝶,雨非雨,让渺远的梵音穿透天空,直到天之外。伸手,握不住岁月的苍凉。

欢迎大佬留言








原文地址:https://www.cnblogs.com/dfym80/p/12849383.html