SpringBoot(七)整合themeleaf+bootstrap

本文介绍了如何在SpringBoot项目中整合Thymeleaf模板引擎和Bootstrap框架。首先阐述了Thymeleaf的作用和特性,然后展示了如何在SpringBoot的配置文件中设置Thymeleaf参数。接着,创建了一个新的Controller以处理视图解析,并通过Model传递数据到页面。最后,创建了mynearby.html页面,使用Thymeleaf语法和Bootstrap样式展示数据。
摘要由CSDN通过智能技术生成

前言

Thymeleaf是用于Web和独立环境的现代服务器端Java模板引擎。Thymeleaf的主要目标是将优雅的自然模板带到您的开发工作流程中—HTML能够在浏览器中正确显示,并且可以作为静态原型,从而在开发团队中实现更强大的协作。Thymeleaf能够处理HTML,XML,JavaScript,CSS甚至纯文本。

Spring-boot-starter-web集成了Tomcat以及Spring MVC,会自动配置相关东西,Thymeleaf是用的比较广泛的模板引擎.

更新pom.xml

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

更新application.properties

#thymeleaf

spring.thymeleaf.cache=false

spring.thymeleaf.prefix=classpath:/templates/

spring.thymeleaf.check-template-location=true

spring.thymeleaf.suffix=.html

spring.thymeleaf.encoding=UTF-8

spring.thymeleaf.mode=HTML5

创建Controller

之所以新建Controller,而不是复用之前的IndexController,是因为IndexController使用的是 @RESTController 注解的方式。

1. 使用@Controller 注解,在对应的方法上,视图解析器可以解析return 的jsp,html页面,并且跳转到相应页面。若返回json等内容到页面,则需要加@ResponseBody注解

2. @RestController注解,相当于@Controller+@ResponseBody两个注解的结

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值