加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

【SpringBoot】10.SpringBoot文件上传

发布时间:2020-12-15 07:08:24 所属栏目:Java 来源:网络整理
导读:SpringBoot整合Thymeleaf 1.创建Thymeleaf的入门项目 maven构建简单项目 修改pom文件添加thymeleaf的坐标 !-- thymeleaf的坐标 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-thymeleaf/artifactId/dependency 创建存

SpringBoot整合Thymeleaf

1.创建Thymeleaf的入门项目

  1. maven构建简单项目

  2. 修改pom文件添加thymeleaf的坐标

    <!-- thymeleaf的坐标 -->
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-thymeleaf</artifactId>
    		</dependency>
    
  3. 创建存放视图的目录:src/main/resources/templates

    templates:该目录是安全的,意味着该目录下的内容是不允许外界直接访问的(不能通过url直接访问)。

    1552110920094.png

2.Thymeleaf的基本使用

1.Thymeleaf的特点

Thymeleaf是通过他特定的语法对html的标记做渲染。

2.编写controller
/**
 * Thymeleaf 入门案例
 */
@Controller
public class DemoController {
	@RequestMapping("/show")
	public String showInfo(Model model) {
		model.addAttribute("msg","Thymeleaf 第一个案例");
		return "index";
	}
}
3.编写页面
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Thymeleaf 入门</title>
</head>
<body>
	<span th:text="Hello"></span>
	<hr/>
	<span th:text="${msg}"></span>
</body>
</html>
4.编写启动器
5.运行

有可能会出现没有html结束标记的异常:
我的项目的Springboot的版本是2.1.2所以没有出现此异常

  1. 加上结束标记即可。让html的标记按照严谨的语法编写。
  2. 修改导入的Thymeleaf的jar包的版本到 3.0以上
  <properties>
  	<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
  	<thymeleaf-layout-dialect.version>2.0.4</thymeleaf-layout-dialect.version>
  </properties>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读