SpringBoot怎么访问templates下的html页面

作为SpringBoot初学者,我想知道SpringBoot怎么访问templates下的html页面。搜了一下,各有各的说法。自己动手,不是这儿出问题就是那出问题。把自己的经验写在这里。如有问题,多交流,评论即可……

项目结构:

 

pom.xml:

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

application.properties

spring.thymeleaf.prefix=classpath:/templates/

html1: http://localhost:8080/html/hello1.html

<html>
	
	<head>
	<title>hello1</title>
	</head>

	<body>
	<p>hello1</p>
	<p>访问方式:http://localhost:8080/html/hello1.html</p>
	</body>

</html>

html2:http://localhost:8080/hello2.html

<html>
	
	<head>
	<title>hello2</title>
	</head>

	<body>
	<p>hello2</p>
	<p>访问方式:http://localhost:8080/hello2.html</p>
	</body>

</html>

html3:http://localhost:8080/html

<html>
	<meta charset="utf-8"></meta>
	<head>
	<title>hello3</title>
	</head>

	<body>
	<p>hello3</p>
	<p>访问方式:http://localhost:8080/html</p>
	</body>

</html>

HtmlController:(此处用的是@Controller)

package com.example.demo.controller;

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

@Controller
public class HtmlController
{
	@RequestMapping("/html")
	public String getHtml() {
		System.out.println("hello3");
		return "hello3";
	}
}

 

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值