前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring boot with Thymeleaf

Spring boot with Thymeleaf

作者头像
netkiller old
发布2018-03-06 10:43:03
8800
发布2018-03-06 10:43:03
举报
文章被收录于专栏:NetkillerNetkiller
本文节选自电子书《Netkiller Java 手札》

5.19. Spring boot with Thymeleaf

5.19.1. Maven

代码语言:javascript
复制
	<dependency>  
		<groupId>org.springframework.boot</groupId>  
		<artifactId>spring-boot-starter-thymeleaf</artifactId>  
	</dependency>			

5.19.2. application.properties

代码语言:javascript
复制
#spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.prefix=/WEB-INF/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false	

5.19.3. Controller

代码语言:javascript
复制
package cn.netkiller.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/")
public class HelloController {

	@RequestMapping(value = "/{name}", method = RequestMethod.GET)
	public String getMovie(@PathVariable String name, ModelMap model) {
		model.addAttribute("name", name);
		return "hello";
	}

}			

5.19.4. HTML5 Template

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Spring MVC + Thymeleaf Example</title>
</head>
<body>
	Hello, <span th:text="${name}" />!
</body>
</html>	
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2017-11-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Netkiller 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 本文节选自电子书《Netkiller Java 手札》
  • 5.19. Spring boot with Thymeleaf
    • 5.19.1. Maven
      • 5.19.2. application.properties
        • 5.19.3. Controller
          • 5.19.4. HTML5 Template
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档