SpringBoot + Thymeleaf 之 HelloWorld
目录
■相关知识
■构造
■代码
java
html
pom
yml
■效果
■相关知识
使用JDK中的 keytool【创建证书】・【查看】・【使用】_sun0322-CSDN博客
SpringBoot + MyBatis 之 Hello World_sun0322-CSDN博客
SpringBoot + MyBatis + Thymeleaf 之 HelloWorld_sun0322-CSDN博客
■构造
■代码
java
注意点:不能使用 @RestController
package com.sxz.test.one;import java.time.LocalDateTime;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;// @RestController // 它是无效的。不支持模板引擎
@Controller // 要使用它配置该类
public class HelloThymeleaf {@Autowiredprivate HttpServletRequest request;@Autowiredprivate HttpServletResponse response;@GetMapping("/hello2")public String hello(ModelMap modelMap) {String agentInfo = request.getHeader("user-agent");String showInfo = agentInfo;LocalDateTime ldt = LocalDateTime.now();System.out.println("-------------Access Begin----------------");System.out.println(ldt);System.out.println(showInfo);System.out.println("-------------Access End----------------");modelMap.addAttribute("name",showInfo);//return showInfo;return "helloThymeleaf";}}
html
注意点:要在templates目录下面
---
<html xmlns:th="http://www.thymeleaf.org"><html>
<head><meta charset="UTF-8"><title>helloThymeleaf页面</title>
</head>
<body bgcolor="#FFFF99">
<h1 th:text="${name}" ></h1>
<p>Hello!</p>
</body>
</html>
pom
<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>sxz.com</groupId><artifactId>SpringBootStaduy001</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>SpringBootStaduy001</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.10.RELEASE</version></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><includeSystemScope>true</includeSystemScope></configuration></plugin></plugins>
</build></project>
yml
server.port=443
server.ssl.key-store: .keystore
server.ssl.key-store-password: tomcat
server.ssl.keyStoreType: JKS
server.ssl.keyAlias: myTomcatspring.thymeleaf.enabled:true
spring.thymeleaf.cache: false
spring.thymeleaf.mode: html
■效果
访问
helloThymeleaf页面
----
--
SpringBoot + Thymeleaf 之 HelloWorld相关推荐
- SpringBoot + MyBatis + Thymeleaf 之 HelloWorld
目录 ■相关知识 ■代码 UserController2 helloThymeleafMyBatis.html ■效果 ■DB数据 ■其他(@RestController) 没有使用[Thymelea ...
- Ajax+SpringBoot+Thymeleaf使用中遇到的跳转页面问题
前言:这周在使用 Ajax+Thymeleaf 时遇到一个问题,折腾了我很久,在此记录一下 Ajax+SpringBoot+Thymeleaf使用中遇到的跳转页面问题 问题描述 我的目的:通过 Aja ...
- SpringBoot thymeleaf使用方法,thymeleaf模板迭代
SpringBoot thymeleaf使用方法,thymeleaf模板迭代 SpringBoot thymeleaf 循环List.Map ============================= ...
- SpringBoot Thymeleaf使用教程(实用版)
SpringBoot Thymeleaf使用教程(实用版) 使用Thymeleaf 三大理由: 简洁漂亮 容易理解 完美支持HTML5 使用浏览器直接打开页面 不新增标签 只需增强属性 学习目标 快速 ...
- 最简单最详细的SpringBoot入门项目——HelloWorld
最详细的SpringBoot入门项目--HelloWorld 关于SpringBoot的介绍以及优点这里就不说了,想了解的可以直接点击这里 Spring Boot百度百科 接下来我们直奔主题,开始用S ...
- springboot+thymeleaf+pageHelper带条件分页查询
html层 <div><a class="num"><b th:text="'共 '+ ${result.resultMap['pages' ...
- 基于springboot+thymeleaf+mybatis的员工管理系统 —— 增删改查
员工管理系统 - 增删改查 entity 查询所有功能 查询所有的页面 emplist.html 保存员工 保存员工的页面 addEmp.html 删除员工 修改员工 根据id查询员工 修改员工信息 ...
- 基于springboot+thymeleaf+mybatis的员工管理系统 —— 登录与注册
员工管理系统 - 登录与注册功能 创建项目 pom.xml 数据库表设计和环境准备 建表SQL application.properties 用户注册与登录功能 entity dao service ...
- 基于Springboot + Thymeleaf 的招聘网站(源代码+数据库) 026
部分代码地址 https://gitee.com/ynwynwyn/springboot-recruit-public 基于Springboot + Thymeleaf 的招聘网站(源代码+数据库) ...
最新文章
- 产销对接行动倡议书-万祥军:农民丰收节交易会谋定机制
- 聊一聊Yarp结合Nacos完成服务发现
- html中显示数据库中的一条数据,如何使用html表显示数据库中的数据
- Oracle存储过程(转)
- 从单片机步入Linux之运行地址与加载地址
- “6亿元入股锤子”项目涉嫌国资流失被调查?官方回应来了
- 错误记录(三)identity和assigned 的区别
- 如何将三万行代码从 Flow 移植到 TypeScript?
- 计算机学院特色迎新标语,开学迎新口号
- 三合一收款二维码原理以及源码
- mysql 序系列化_J2SE中的序默认序列化_MySQL
- ellipse函数用法
- sqlserver 抓取所有执行语句 SQL语句分析 死锁 抓取
- C:深入研究MessageBox
- 解决margin塌陷问题
- MySQL Windows安装教程
- 10本 Spring Boot 学习书籍-个人记载
- 快速排序(quickSort)
- matlab进行电机仿真,MATLAB simulink在电机中的仿真.ppt
- Kotlin for 循环写法整理
热门文章
- ddmmyy日期格式是多少_如何在Excel 2013/2016/2019中将mmddyyyy文本转换为普通日期格式...
- python优雅编程_Python——traceback的优雅处理
- 计算机管理教学 (cmi) 包括( )等功能,计算机管理教学(CMI)的未来
- baidu google 下拉框 的简单实现
- selenium java api_selenium_java常用API操作
- dnf如何快速拾取物品_极简断舍离|如何快速处理闲置物品?
- c++调用栈库函数_大华 | C/C++ 校招笔试题
- hanlp和jieba等六大中文分工具的测试对比
- Firebug无法添加到最新版firefox55.0.*中解决办法
- int 和String之间的互转