SpringBoot+Thyemleaf
- <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.imooc</groupId>
- <artifactId>miaosha_1</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>jar</packaging>
- <name>miaosha_1</name>
- <url>http://maven.apache.org</url>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>1.5.9.RELEASE</version>
- </parent>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
- <dependencies>
- <!--springBoot-->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <!--thymeleaf-->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-thymeleaf</artifactId>
- </dependency>
- </dependencies>
- </project>
- 2.SpringBoot会默认在resources下查找application.properties的配置文件。
- application.properties用来配置Thyemleaf的池
- #缓存
- spring.thymeleaf.cache=false
- #文本
- spring.thymeleaf.content-type=text/html
- #启用
- spring.thymeleaf.enabled=true
- #编码
- spring.thymeleaf.encoding=UTF-8
- #页面
- spring.thymeleaf.mode=HTML5
- #前缀
- sprin.thymeleaf.prefix=classpath:/templates/
- #后缀
- spring.thymeleaf.suffix=.html
- 3.在配置的前缀文件下 编写html页面
- <!DOCTYPE HTML>
- <html xmlns:th="http://www.thymeleaf.org">
- <head>
- <title>hello</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- </head>
- <body>
- <p th:text="'hello:'+${name}" ></p>
- </body>
- </html>
- 4.control控制
- @Controlle
@RequestMapping("/demo")
public class DemoController {- @RequestMapping("/")
- @ResponseBody
- String home() {
- return "Hello World!";
- }
- //1.rest api json输出 2.页面
- @RequestMapping("/hello")
- @ResponseBody
- public Result<String> hello() {
- return Result.success("hello,imooc");
- // return new Result(0, "success", "hello,imooc");
- }
- @RequestMapping("/helloError")
- @ResponseBody
- public Result<String> helloError() {
- return Result.error(CodeMsg.SERVER_ERROR);
- //return new Result(500102, "XXX");
- }
- /**
- * thymeleaf测试的主要方法
- * @param model
- * @return
- */
- @RequestMapping("/thymeleaf")
- public String thymeleaf(Model model) {
- model.addAttribute("name", "Joshua");
- return "hello";
- }
- }
- 5.程序的入口mian方法。
SpringBoot有两个常用的注解,一个是@controller
另一个是@EnableAutoConfiguration,但是一般不使用这个而是用- @SpringBootApplication
- 如下整个项目就能正常启动了
SpringBoot+Thyemleaf的更多相关文章
- SpringBoot+Thyemleaf开发环境正常,打包jar发到服务器就报错Template might not exist or might not be accessible
网上查看了各种解决的思路,总结如下: 1. 在controller层请求处理完了返回时,没有使用@RestController或@ResponseBody而返回了非json格式 这种情况下返回的数据t ...
- Springboot的static和templates区别
static和templates部分参考博客:https://blog.csdn.net/wangb_java/article/details/71775637 热部署参考博客:https://www ...
- shiro三连斩之第三斩,整合 springboot
shiro爱springboot中使用 ,还有thymeleaf前端框架.主要是如何配置 pom.xml配置依赖 <?xml version="1.0" encoding=& ...
- Springboot的static和templates
static和templates部分参考博客:https://blog.csdn.net/wangb_java/article/details/71775637 热部署参考博客:https://www ...
- springBoot 基础入门
来处:是spring项目中的一个子项目 优点 (被称为搭建项目的脚手架) 减少一切xml配置,做到开箱即用,快速上手,专注于业务而非配置 从创建项目上: -- 快速创建独立运 ...
- SpringBoot 整合 Thymeleaf & 如何使用后台模板快速搭建项目
如果你和我一样,是一名 Java 道路上的编程男孩,其实我不太建议你花时间学 Thymeleaf,当然他的思想还是值得借鉴的.但是他的本质在我看来就是 Jsp 技术的翻版(Jsp 现在用的真的很少很少 ...
- 【SpringBoot实战】视图技术-Thymeleaf
前言 在一个Web应用中,通常会采用MVC设计模式实现对应的模型.视图和控制器,其中,视图是用户看到并与之交互的界面.对最初的Web应用来说,视图是由HTML元素组成的静态界面:而后期的Web应用更倾 ...
- 解决 Springboot Unable to build Hibernate SessionFactory @Column命名不起作用
问题: Springboot启动报错: Caused by: org.springframework.beans.factory.BeanCreationException: Error creati ...
- 【微框架】Maven +SpringBoot 集成 阿里大鱼 短信接口详解与Demo
Maven+springboot+阿里大于短信验证服务 纠结点:Maven库没有sdk,需要解决 Maven打包找不到相关类,需要解决 ps:最近好久没有写点东西了,项目太紧,今天来一篇 一.本文简介 ...
随机推荐
- 「中国剩余定理CRT」学习笔记
设正整数$m_1, m_2, ... , m_r$两两互素,对于同余方程组 $x ≡ a_1 \ (mod \ m_1)$ $x ≡ a_2 \ (mod \ m_2)$ $...$ $x ≡ a_r ...
- 【XSY2718】gift 分数规划 网络流
题目描述 有\(n\)个物品,买第\(i\)个物品要花费\(a_i\)元.还有\(m\)对关系:同时买\(p_i,q_i\)两个物品会获得\(b_i\)点收益. 设收益为\(B\),花费为\(A\), ...
- session的基本原理及安全性
1.session原理 提到session,大家肯定会联想到登录,登录成功后记录登录状态,同时标记当前登录用户是谁.功能大体上就是这个样子,但是今天要讲的不是功能,而是实现.通过探讨session的实 ...
- linux下对clamav杀毒软件的安装和配置
下载安装 首先安装zlib库: # yum install zlib zlib-devel //安装可忽略 下载安装clamav源码包 clamav管网:http://www.clamav.net/d ...
- PHP慢日子查询
2开启慢日志配置输出php-fpm慢日志,阀值为2秒:request_slowlog_timeout = 2slowlog = log/$pool.log.slow利用sort/uniq命令分析汇总p ...
- 数据库设计E-R图
项目数据库的设计主要划分为以下6个阶段,本篇主要着重来介绍概念设计阶段 A.系统需求分析阶段B.概念结构设计阶段C.逻辑结构设计阶段D.物理结构设计阶段E.数据库实施阶段F.数据库运行与维护阶段 E- ...
- Linux里文件和文件夹权限的含义
文件的权限: r : 可以读取此文件的实际内容. w: 可以编辑.新增或者是修改该文件的内容(但不含删除该文件),如果没有r权限,无法w. x : 该文件具有被系统执行的权限,可以删除. 文件夹的 ...
- mysql 远程连接 10038
1,先确认本地是否能连上本地能连上就对用户进行授权 mysql>grant all privileges on *.* to 'root'@'%' identified by 'youpassw ...
- springboot 通过 hibernate 连接sqlserver 空间数据 位置数据
示例代码:https://github.com/bigben0123/spring-boot-spatial-example 1,配置application.properties #sqlserver ...
- 使用selenium 模拟人操作请求网页
首先要 pip install selenium 安装插件 然后要下载驱动驱动根据你的浏览器 Chrome selenium 驱动下载地址 http://chromedriver.storage. ...