spring boot 整合 thymeleaf
来源:互联网 发布:淘宝店铺投诉电话 编辑:程序博客网 时间:2024/04/29 00:01
一:介绍
如果Spring boot在类路径中对配置进行扫描,它将自动配置。我们可以使用application.properties更改默认的配置。thymeleaf是一个可以处理XML、HTML等的服务器端模板引擎,它可以访问一个类字段,从i18n消息文件中获取消息属性。我们可以使用thymymf将类字段与HTML表单元素绑定在一起。我们还将提供如何使用Maven,如果Spring启动启动器使用的是较低版本的thymeleaf,则使用Maven来使用更高版本。我们还将使用我们的Thymeleaf view 的CSS文件。
二: 新建项目
三: 创建Maven文件
找到本例中使用的Maven文件。
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.xphsc</groupId> <artifactId>eglsc-thymeleaf</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <url>http://maven.apache.org</url> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.5.RELEASE</version> </parent><dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.26</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.24</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.12</version> </dependency>
<dependency> <groupId>com.github.xphsc</groupId> <artifactId>eglsc-helper</artifactId> <version>1.2.0</version> </dependency></dependencies></project>
找到spring boot启动器的描述。
spring-boot-starter-parent:父项目POM用于依赖关系管理。
spring-boot-starter-web::构建web、REST应用程序的启动器。它使用tomcat服务器作为默认的嵌入式服务器
spring-boot-starter-thymeleaf spring boot 配置thymeleaf模板引擎
2:创建application.properties,application-dev.yml
在Spring boot中,为了配置与数据库相关的属性、Hibernate和日志,我们需要使用application.properties。我们正在使用JPA规范的Hibernate实现。
application.properties
创建 thymeleaf模板页面(index.html)server.port=8082spring.profiles.active=devlogging.level.root= INFOlogging.level.org.springframework.web= ERRORlogging.level.com.xphsc= INFOapplication-dev.yml
spring: thymeleaf: prefix: classpath:/WEB-INF/views/ mode: HTML5 encoding: UTF-8 content-type: text/html cache: true datasource: name: test_mysql url: jdbc:mysql://localhost:3306/test_mysql?useUnicode=true&characterEncoding=UTF-8 username: root password: root type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver filters: stat maxActive: 20 initialSize: 1 maxWait: 60000 minIdle: 1 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 'x' testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxOpenPreparedStatements: 20<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"><head><meta charset="UTF-8" /><title>Insert title here</title></head><body><h4 th:text="${msg}"></h4></body></html>创建访问页面控制器controller(ViewController)@Controllerpublic class ViewController { @RequestMapping("/index") public String index(Model model){ model.addAttribute("msg","欢迎进入index页面"); return "index"; }}创建 spring boot启动类
@SpringBootApplicationpublic class Application { public static void main(String[] args) { new SpringApplicationBuilder() .sources(Application.class) .bannerMode(Banner.Mode.CONSOLE) .run(args); }3 :运行spring boot 的启动类 就可以访问自己定义好的页面(如图)*********************************************
2
阅读全文
0 0
- spring boot 整合 thymeleaf
- Spring Boot整合thymeleaf
- spring-boot--整合thymeleaf模板
- spring-boot--整合thymeleaf模板
- Spring Boot(4)整合thymeleaf
- Spring Boot 整合 Thymeleaf 完整 Web 案例
- Spring Boot 整合 Thymeleaf 完整 Web 案例
- Spring Boot整合Thymeleaf模板引擎
- Spring boot项目整合thymeleaf和shiro
- spring boot 学习(二)spring boot 框架整合 thymeleaf
- spring boot 学习(二)spring boot 框架整合 thymeleaf
- spring boot 使用thymeleaf 和shiro标签整合
- (五)Spring Boot配置静态资源访问,整合Thymeleaf模板
- [spring-boot] thymeleaf 热交换
- Spring Boot + Gradle + Thymeleaf
- spring boot vue Thymeleaf
- spring boot thymeleaf 用法
- Spring Boot使用Thymeleaf
- 欢迎使用CSDN-markdown编辑器
- 例题1.4 Graveyard UVALive
- mysql --- join ,where
- printf 的宏定义版本
- scrapy提示DEBUG:Filtered offsite request to
- spring boot 整合 thymeleaf
- Java程序的组织形式和命名规则
- Hibernate的三种状态以及状态的转换:
- 判断日期是否过期,以及根据日期判断周几
- 几大主流视频播放器观看VIP视频
- 《软件测试经验与教训》读书笔记
- 股票、证券等(个人)商业投资
- Maven安装教程、集成到eclipse
- 我的spring 下