zoukankan      html  css  js  c++  java
  • 【SpringBoot】10.SpringBoot文件上传

    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>
    
  • 相关阅读:
    android原子
    android进程优先级
    Android 的cyclicBarrier
    android中运用CountDownLatch
    java网络编程长连接的问题
    https
    http 上传文件
    netty4 断线重连
    Linux下高并发socket最大连接数所受的各种限制
    Android Studio NDK及so文件开发
  • 原文地址:https://www.cnblogs.com/isdxh/p/13529126.html
Copyright © 2011-2022 走看看