Springboot使用thymeleaf进行页面跳转

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_38959210/article/details/80420258

需要修改两处文件。

1.pom文件, <!-- 引入 thymeleaf 模板依赖 -->

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

2..application.properties文件,新增下面配置。

spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false

3.java代码 如下方式,就可以跳转到html页面

@ControllerAdvice
@RequestMapping("index")
public class SpringBootController {
	
@RequestMapping("/index")
	public String index() {
		
		return "ziyong/index";
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_38959210/article/details/80420258
今日推荐