0
点赞
收藏
分享

微信扫一扫

Springboot(十七)SpringBoot整合thymeleaf


新建一个springboot工程,加入thymeleaf依赖:

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

application.properties文件:

spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=utf-8
spring.thymeleaf.enabled=true
spring.thymeleaf.servlet.content-type=text/html

在src/main/java/resources/templates下新建一个hello.html文件

Springboot(十七)SpringBoot整合thymeleaf_thymeleaf

 

建一个controller

package com.xhx.springboot.controller;

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

import java.util.Map;

/**
* xuhaixing
* 2018/8/18 22:10
*
* thymeleaf3.0之前 html标签需要闭合,之后不需要
**/
@Controller
@RequestMapping(value = "templates")
public class HelloController {

@RequestMapping("hello")
public String getHello(Map<String,Object> map){
map.put("name","大大");
return "hello";
}
}

启动程序请求,会跳转到hello.html页面

实时内容请关注微信公众号,公众号与博客同时更新:程序员星星

Springboot(十七)SpringBoot整合thymeleaf_html_02

举报

相关推荐

0 条评论