首页 > 编程语言 > 详细

springboot controller templates html

时间:2020-05-08 12:59:25      阅读:57      评论:0      收藏:0      [点我收藏+]

首先声明:

  @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{
width: 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技术分享图片

 

 技术分享图片

 

 

总结:

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

 

欢迎大佬留言


 






springboot controller templates html

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!