美文网首页
使用idea搭建Spring Boot项目(三)配置静态页面及传

使用idea搭建Spring Boot项目(三)配置静态页面及传

作者: Jinwei_ | 来源:发表于2020-07-17 17:44 被阅读0次

一、配置静态页面

1、pom.xml中添加模板配置

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

2、application.properties中添加静态文件查找目录

# 定位模板的目录
spring.mvc.view.prefix=classpath:/templates/
# 给返回的页面添加后缀名
spring.mvc.view.suffix=.html

3、controller文件

@GetMapping("/index") //根据application.properties添加的配置,查找index文件
 public String index(){
   return "home"; //当浏览器输入/index时,会返回 /templates/home.html页面
}

4、在templates新建html静态页面,示例代码

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

5、浏览器输入

http://localhost:8080

二、参数传递至页面

相关文章

网友评论

      本文标题:使用idea搭建Spring Boot项目(三)配置静态页面及传

      本文链接:https://www.haomeiwen.com/subject/clcnhktx.html