SpringBoot学习9:springboot整合thymeleaf
1、创建maven项目,添加项目所需依赖
<!--springboot项目依赖的父项目-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent> <dependencies>
<!--注入springboot启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <!--注入springboot对thymeleaf视图技术的支持-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
2、创建controller
package com.bjsxt.controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; /**
* Created by Administrator on 2019/2/8.
*/
@Controller
public class IndexController { @RequestMapping("/toIndex")
public String toIndex(Model model){
model.addAttribute("msg","index页面");
return "index";
}
}
3、创建thymeleaf模版文件index.html
目录位置:src/main/resources/templates
templates:该目录是安全的。意味着该目录下的内容是不允许外界直接访问的。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>thymeleaf</title>
</head>
<body>
<span th:text="${msg}"></span>
<hr>
<span th:text="hello"></span>
</body>
</html>
4、创建启动器,启动在浏览器中访问
package com.bjsxt; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; /**
* Created by Administrator on 2019/2/8.
*/
@SpringBootApplication
public class App { public static void main(String[] args){
SpringApplication.run(App.class,args);
}
}
目录结构

SpringBoot学习9:springboot整合thymeleaf的更多相关文章
- SpringBoot学习- 4、整合JWT
SpringBoot学习足迹 1.Json web token(JWT)是为了网络应用环境间传递声明而执行的一种基于JSON的开发标准(RFC 7519),该token被设计为紧凑且安全的,特别适用于 ...
- SpringBoot学习- 3、整合MyBatis
SpringBoot学习足迹 1.下载安装一个Mysql数据库及管理工具,同类工具很多,随便找一个都可以,我在windows下做测试项目习惯使用的是haosql 它内部集成了MySql-Front管理 ...
- SpringBoot学习- 5、整合Redis
SpringBoot学习足迹 SpringBoot项目中访问Redis主要有两种方式:JedisPool和RedisTemplate,本文使用JedisPool 1.pom.xml添加dependen ...
- 【Java Web开发学习】Spring4整合thymeleaf视图解析
[Java Web开发学习]Spring4整合thymeleaf视图解析 目录 1.简单介绍2.简单例子 转载:https://www.cnblogs.com/yangchongxing/p/9111 ...
- SpringBoot学习- 8、整合Shiro
SpringBoot学习足迹 Shiro是什么,引自百度百科:Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码和会话管理.使用Shiro的易于理解的API,您可以快 ...
- springboot学习笔记-4 整合Druid数据源和使用@Cache简化redis配置
一.整合Druid数据源 Druid是一个关系型数据库连接池,是阿里巴巴的一个开源项目,Druid在监控,可扩展性,稳定性和性能方面具有比较明显的优势.通过Druid提供的监控功能,可以实时观察数据库 ...
- springboot学习笔记-3 整合redis&mongodb
一.整合redis 1.1 建立实体类 @Entity @Table(name="user") public class User implements Serializable ...
- springboot学习四:整合mybatis
在application.properties加入配置 ## Mybatis 配置 mybatis.typeAliasesPackage=org.spring.springboot.domain my ...
- springboot学习三:整合jsp
在pom.xml加入jstl <!--springboot tomcat jsp 支持开启--> <dependency> <groupId>org.apache. ...
- 十一、springboot(六)整合Thymeleaf
1.添加jar包依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId ...
随机推荐
- OpenStack Weekly Rank 2015.08.03
Module Reviews Drafted Blueprints Completed Blueprints Filed Bugs Resolved Bugs Cinder 7 1 1 7 11 Sw ...
- 本机访问其它电脑上的oracle数据库
最近发现很多人问到怎么才能访问别人机子上的oracle,这里来给大家做个示范 借助工具的话,oracle就自己带了两个配置和移值助手下面:net configuration assistant 和ne ...
- [巩固C#] 三、依赖注入是什么?
阅读目录 接口 在说依赖注入之前,先了解下什么是接口. 我们在学编程的时候都知道,接口的相关规则:(来源百度百科) 1. 接口是一个引用类型,通过接口可以实现多重继承. 2. C#中接口的成员不能 ...
- [转]Asp.net Core中使用Session
本文转自:http://www.cnblogs.com/sword-successful/p/6243841.html 前言 2017年就这么悄无声息的开始了,2017年对我来说又是特别重要的一年. ...
- node搭环境(二)之 bower gulp
前面详细记录了安装node及git,接来下要安装bower,首先创建一个空文件夹bowerandgulp. 步骤:1.安装node.js 2.node里面自带了 npm 3.通过npm 安装cnpm ...
- mysql 将null转代为0(转)
1.如果为空返回0 select ifnull(null,0) 2.如果为空返回0,否则返回1 select if(isnull(col),0,1) as col. MYSQL 中的IFNULL函数 ...
- 处理http请求时,如何处理url的参数
1.@PathVariable 获取url中的数据 这种写法显得简洁 也可以把参数写在前面 @RequestParam 获取请求参数的值 适合传统的get提交参数的获取 给参数id设置一个默认值 不传 ...
- 从零开始的全栈工程师——js篇2.18(js的运动)
一.元素的 client offset scroll 三个系列 clientWidth / clientHeight / clientTop / clientLeftoffsetWidth / off ...
- [原创]在Debian9上配置NAS
序言 此教程安装的都是最新版本的.由于是当NAS让它非常稳定的运行,所以能不安装的软件尽量不要安装. 一.准备工作 1. 更新系统 没啥,就他喵想用个最新的. apt update && ...
- POJO详解
转自:http://blog.csdn.net/lushuaiyin/article/details/7436318 一:什么是POJO POJO的名称有多种,pure old java objec ...