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:最近好久没有写点东西了,项目太紧,今天来一篇 一.本文简介 ...
随机推荐
- Codeforces Round #545 (Div. 2) D
链接:http://codeforces.com/contest/1138/problem/D 啊啊啊啊啊啊,自闭啊,比赛的时候判断条件 if(s1[i-1]=='0') aa++;写成了 if(s1 ...
- project 2013 显示标题
1.分析 右键只能插入任务,不能插入标题,而插入任务会被编号,目前只能在打印设置标题,不能在编辑界面显示标题的,或者使用最高级任务的方式 2.解决 文件,打印,页面设置,页眉,居中,输入标题,这样打印 ...
- 本文之后都以Vol1来指代
本文参考文档是<64-ia-32-architectures-software-developer-vol-1-manual>(本文之后都以Vol1来指代),介绍了x86架构的基础.这些基 ...
- Hdoj 1115.Lifting the Stone 题解
Problem Description There are many secret openings in the floor which are covered by a big heavy sto ...
- 【Linux命令】linux一次性解压多个.gz或者.tar.gz文件
原文:linux一次性解压多个.gz或者.tar.gz文件 解压多个压缩包 对于解压多个.gz文件的,用此命令: for gz in *.gz; do gunzip $gz; done 对于解压多个. ...
- 【BZOJ4008】[HNOI2015]亚瑟王(动态规划)
[BZOJ4008][HNOI2015]亚瑟王(动态规划) 题面 BZOJ 洛谷 题解 设\(f[i][j]\)表示前\(i\)张卡中有\(j\)张被触发的概率. 分两种情况转移,即当前这张是否被触发 ...
- js笔记-语句,变量
JavaScript介绍 JavaScript是运行在浏览器端的脚步语言,JavaScript主要解决的是前端与用户交互的问题,包括使用交互与数据交互. JavaScript是浏览器解释执行的,前端脚 ...
- 「NOI2014」购票 解题报告
「NOI2014」购票 写完了后发现写的做法是假的...然后居然过了,然后就懒得管正解了. 发现需要维护凸包,动态加点,询问区间,强制在线 可以二进制分组搞,然后你发现在树上需要资瓷撤回,然后暴力撤回 ...
- One-hot encoding 独热编码
http://blog.sina.com.cn/s/blog_5252f6ca0102uy47.html
- bzoj3702/bzoj2212 二叉树 (线段树合并)
用线段树记每个子树中包含的数,然后合并的时候算出来逆序对的数量(合并a,b时,就是size[ch[a][1]]*size[ch[b][0]]),来决定这个子树要不要翻转 #include<bit ...
