如何在 Spring Boot 项目中使用 Thymeleaf 和 Bootstrap 实现文件上传

news2024/9/23 15:26:12

在本教程中,我将向您展示如何在 Spring Boot 项目中使用 Thymeleaf 和 Bootstrap 实现文件上传。我们还使用 Spring Web MultipartFile界面来处理 HTTP 多部分请求。

Thymeleaf 文件上传概述

我们的 Spring Boot + Thymeleaf 文件上传示例将具有以下功能:

  • 将文件上传到服务器中的静态文件夹
  • 使用链接从服务器下载文件
  • 获取文件信息列表(文件名和URL)

– 这是文件上传表格:

 

– 如果文件超过特定的最大大小:

 

– 这是存储所有上传文件的静态文件夹:

 

– 您可以查看带有下载链接的上传文件列表:

 

在本教程中,我不解释删除文件的方法。如果你想知道这一点,只需访问:
弹簧启动删除文件示例与百里香叶

或者使用以下教程添加分页:
春季启动百里香叶分页示例

科技

  • Java 8
  • Spring Boot 2.7 (with Spring Web MVC, Thymeleaf)
  • Maven 3.6.1
  • Bootstrap 4
  • jQuery 3.6.1

项目结构

 

让我简要解释一下。

FileInfo包含上传文件的信息。

FilesStorageService帮助我们初始化存储,保存新文件,加载文件,获取文件信息列表,删除文件。

FileController、FilesStorageService用于处理文件上传/下载和模板请求。

FileUploadExceptionAdvice在控制器处理文件上传时处理异常。

template存储项目的 HTML 模板文件。

– application.properties包含 Servlet Multipart 的配置。
– uploads上传是用于存储文件的静态文件夹。
– pom.xml 用于 Spring Boot 依赖项。

创建和设置 Spring Boot 项目

使用 Spring Web 工具或开发工具(Spring Tool Suite、Eclipse、Intellij)创建 Spring Boot 项目。

然后打开pom.xml并为Spring Web,Thymeleaf,Bootstrap,Jquery添加依赖项:

<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>org.webjars</groupId>
	<artifactId>bootstrap</artifactId>
	<version>4.6.2</version>
</dependency>

<dependency>
	<groupId>org.webjars</groupId>
	<artifactId>jquery</artifactId>
	<version>3.6.1</version>
</dependency>

<dependency>
	<groupId>org.webjars</groupId>
	<artifactId>webjars-locator-core</artifactId>
</dependency>

为文件存储创建服务

首先,我们需要一个将在控制器中自动连接的接口。
服务文件夹中,创建类似于以下代码的接口:FilesStorageService

service/FilesStorageService.java

package com.bezkoder.spring.thymeleaf.file.upload.service;

import java.nio.file.Path;
import java.util.stream.Stream;

import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile;

public interface FilesStorageService {
  public void init();

  public void save(MultipartFile file);

  public Resource load(String filename);
  
  public void deleteAll();

  public Stream<Path> loadAll();
}

现在我们创建接口的实现。

service/FilesStorageServiceImpl.java

package com.bezkoder.spring.thymeleaf.file.upload.service;

import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Service;
import org.springframework.util.FileSystemUtils;
import org.springframework.web.multipart.MultipartFile;

@Service
public class FilesStorageServiceImpl implements FilesStorageService {
  private final Path root = Paths.get("./uploads");

  @Override
  public void init() {
    try {
      Files.createDirectories(root);
    } catch (IOException e) {
      throw new RuntimeException("Could not initialize folder for upload!");
    }
  }

  @Override
  public void save(MultipartFile file) {
    try {
      Files.copy(file.getInputStream(), this.root.resolve(file.getOriginalFilename()));
    } catch (Exception e) {
      if (e instanceof FileAlreadyExistsException) {
        throw new RuntimeException("A file of that name already exists.");
      }

      throw new RuntimeException(e.getMessage());
    }
  }

  @Override
  public Resource load(String filename) {
    try {
      Path file = root.resolve(filename);
      Resource resource = new UrlResource(file.toUri());

      if (resource.exists() || resource.isReadable()) {
        return resource;
      } else {
        throw new RuntimeException("Could not read the file!");
      }
    } catch (MalformedURLException e) {
      throw new RuntimeException("Error: " + e.getMessage());
    }
  }

  @Override
  public void deleteAll() {
    FileSystemUtils.deleteRecursively(root.toFile());
  }

  @Override
  public Stream<Path> loadAll() {
    try {
      return Files.walk(this.root, 1).filter(path -> !path.equals(this.root)).map(this.root::relativize);
    } catch (IOException e) {
      throw new RuntimeException("Could not load the files!");
    }
  }
}

创建用于文件上传的控制器

控制器包中,我们创建 .FileController

控制器/文件控制器.java

package com.bezkoder.spring.thymeleaf.file.upload.controller;
// ...
import com.bezkoder.spring.thymeleaf.file.upload.service.FilesStorageService;

@Controller
public class FileController {

  @Autowired
  FilesStorageService storageService;

  @GetMapping("/")
  public String homepage() {
    return "redirect:/files";
  }

  @GetMapping("/files/new")
  public String newFile(Model model) {
    return "upload_form";
  }

  @PostMapping("/files/upload")
  public String uploadFile(Model model, @RequestParam("file") MultipartFile file) {
    ...

    return "upload_form";
  }

  @GetMapping("/files")
  public String getListFiles(Model model) {
    ...

    return "files";
  }

  @GetMapping("/files/{filename:.+}")
  public ResponseEntity<Resource> getFile(@PathVariable String filename) {
    ...

    // return File
  }
}

@Controller注释用于定义控制器。
@GetMapping、@PostMapping注释用于将 HTTP GET & POST 请求映射到特定的处理程序方法并返回适当的模板文件。
– ​​​​​​​​​​​​​​@Autowired我们使用将FilesStorageService bean 的实现注入到局部变量中。

设置模板

在 src/main/resources 文件夹中,按以下结构创建文件夹和文件:

 

页眉和页脚

我们将使用百里香叶碎片()来重用一些常见的部分,例如页眉和页脚。
让我们为它们编写 HTML 代码。th:fragment

fragments/footer.html

<footer class="text-center">
  Copyright © BezKoder
</footer>

以及包含导航栏的标题:

fragments/header.html

<header th:fragment="header">
  <nav class="navbar navbar-expand-md bg-dark navbar-dark mb-3">
    <a class="navbar-brand" th:href="@{/files}">
      BezKoder
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#topNavbar">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="topNavbar">
      <ul class="navbar-nav">
        <li class="nav-item">
          <a class="nav-link" th:href="@{/files/new}">Upload</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" th:href="@{/files}">Files</a>
        </li>
      </ul>
    </div>
  </nav>
</header>

现在我们需要创建HTML文件,然后导入Thymeleaf片段,Bootstrap,jQuery和Font Awesome。

文件上传表格

upload_form.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0" />
  <title>BezKoder - Thymeleaf File Upload example</title>
  <link rel="stylesheet" type="text/css" th:href="@{/webjars/bootstrap/css/bootstrap.min.css}" />
  <script type="text/javascript" th:src="@{/webjars/jquery/jquery.min.js}"></script>
  <script type="text/javascript" th:src="@{/webjars/bootstrap/js/bootstrap.min.js}"></script>
</head>

<body>
  <div th:replace="fragments/header :: header"></div>

  -- file upload form --

  <div th:replace="fragments/footer :: footer"></div>
</body>

</html>

文件列表

files.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0" />
  <title>BezKoder - Thymeleaf File Upload example</title>

  <link rel="stylesheet" type="text/css" th:href="@{/webjars/bootstrap/css/bootstrap.min.css}" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css"
    integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A=="
    crossorigin="anonymous" referrerpolicy="no-referrer" />
  <script type="text/javascript" th:src="@{/webjars/jquery/jquery.min.js}"></script>
  <script type="text/javascript" th:src="@{/webjars/bootstrap/js/bootstrap.min.js}"></script>
</head>

<body>
  <div th:replace="fragments/header :: header"></div>

  -- list of files display --
  
  <div th:replace="fragments/footer :: footer"></div>
</body>

</html>

实现文件上传功能

我们使用@GetMapping@PostMapping注释用于将HTTP GET和POST请求映射到特定的处理程序方法:​​​​​​​

  • 获取/文件/新: newFile()– 返回upload_form.html模板
  • 发布/文件/上传: uploadFile()– 上传文件

FileController.java

import com.bezkoder.spring.thymeleaf.file.upload.service.FilesStorageService;

@Controller
public class FileController {

  @Autowired
  FilesStorageService storageService;

  @GetMapping("/files/new")
  public String newFile(Model model) {
    return "upload_form";
  }

  @PostMapping("/files/upload")
  public String uploadFile(Model model, @RequestParam("file") MultipartFile file) {
    String message = "";

    try {
      storageService.save(file);

      message = "Uploaded the file successfully: " + file.getOriginalFilename();
      model.addAttribute("message", message);
    } catch (Exception e) {
      message = "Could not upload the file: " + file.getOriginalFilename() + ". Error: " + e.getMessage();
      model.addAttribute("message", message);
    }

    return "upload_form";
  }
}

upload_form.html

<div class="container" style="max-width: 500px">
  <h3 class="mb-3">Thymeleaf File Upload example</h3>

  <form
    id="uploadForm"
    method="post"
    th:action="@{/files/upload}"
    enctype="multipart/form-data">
    <input id="input-file" type="file" name="file" />
    <button class="btn btn-sm btn-outline-success float-right" type="submit">
      Upload
    </button>
  </form>

  <div
    th:if="${message != null}"
    class="alert alert-secondary alert-dismissible fade show text-center message mt-3"
    role="alert">
    [[${message}]]
    <button type="button" class="close btn-sm" data-dismiss="alert" aria-label="Close">
      <span aria-hidden="true">×</span>
    </button>
  </div>
</div>

显示文件列表

首先,我们需要创建具有字段的模型:&.FileInfonameurl

model/FileInfo.java

package com.bezkoder.spring.thymeleaf.file.upload.model;

public class FileInfo {
  
  private String name;
  private String url;

  public FileInfo(String name, String url) {
    this.name = name;
    this.url = url;
  }

  public String getName() {
    return this.name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getUrl() {
    return this.url;
  }

  public void setUrl(String url) {
    this.url = url;
  }
}

在控制器中,我们将返回FileInfo对象列表作为模型属性。
@GetMapping、@PostMapping注释用于将 HTTP GET & POST 请求映射到特定的处理程序方法:​​​​​​​

  • 获取/文件:getListFiles() – 返回文件.html模板
  • 获取 /files/[文件名]:getFile() – 下载​​​​​​​filename文件

FileController.java

import com.bezkoder.spring.thymeleaf.file.upload.model.FileInfo;
import com.bezkoder.spring.thymeleaf.file.upload.service.FilesStorageService;

@Controller
public class FileController {

  @Autowired
  FilesStorageService storageService;

  // ...

  @GetMapping("/")
  public String homepage() {
    return "redirect:/files";
  }

  @GetMapping("/files")
  public String getListFiles(Model model) {
    List<FileInfo> fileInfos = storageService.loadAll().map(path -> {
      String filename = path.getFileName().toString();
      String url = MvcUriComponentsBuilder
          .fromMethodName(FileController.class, "getFile", path.getFileName().toString()).build().toString();

      return new FileInfo(filename, url);
    }).collect(Collectors.toList());

    model.addAttribute("files", fileInfos);

    return "files";
  }

  @GetMapping("/files/{filename:.+}")
  public ResponseEntity<Resource> getFile(@PathVariable String filename) {
    Resource file = storageService.load(filename);

    return ResponseEntity.ok()
        .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getFilename() + "\"").body(file);
  }
}

files.html

<div class="container-fluid" style="max-width: 600px; margin: 0 auto;">
  <h2 class="text-center">List of Files</h2>

  <div th:if="${files.size() > 0}">
    <table class="table table-hover">
      <thead class="thead-light">
        <tr>
          <th scope="col">File Name</th>
          <th scope="col">Link</th>
          <th scope="col">Actions</th>
        </tr>
      </thead>
      <tbody>
        <tr th:each="file : ${files}">
          <td>[[${file.name}]]</td>
          <td><a th:href="@{${file.url}}">Download</a></td>
          <td>
            <a th:href="@{'/files/delete/' + ${file.name}}" th:fileName="${file.name}" id="btnDelete"
              title="Delete this file" class="fa-regular fa-trash-can icon-dark btn-delete"></a>
          </td>
        </tr>
      </tbody>
    </table>
  </div>

  <div th:unless="${files.size() > 0}">
    <span>No files found!</span>
  </div>
</div>

要删除文件,请访问以下教程:
弹簧启动删除文件示例与百里香叶

为 Servlet 配置多部分文件

让我们定义可以在 application.properties 中上传的最大文件大小,如下所示:

spring.servlet.multipart.max-file-size=1MB
spring.servlet.multipart.max-request-size=1MB

– spring.servlet.multipart.max-file-size:每个请求的最大文件大小。
– ​​​​​​​spring.servlet.multipart.max-request-size:多部分/表单数据的最大请求大小。

处理文件上传异常

这是我们处理请求超过最大上传大小的情况的地方。系统将抛出MaxUploadSizeExceededException,我们将使用@ControllerAdvice和@ExceptionHandler注释来处理异常。​​​​​​​​​​​​​​

exception/FileUploadExceptionAdvice.java

package com.bezkoder.spring.thymeleaf.file.upload.exception;

import org.springframework.web.multipart.MaxUploadSizeExceededException;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class FileUploadExceptionAdvice {

  @ExceptionHandler(MaxUploadSizeExceededException.class)
  public String handleMaxSizeException(Model model, MaxUploadSizeExceededException e) {
    model.addAttribute("message", "File is too large!");

    return "upload_form";
  }
}

初始化存储

我们需要运行FilesStorageService init()方法(如有必要​​​​​​​​​​​​​​deleteAll())。所以打开ThymeleafFileUploadApplication.java并实现​​​​​​​CommandLineRunnerrun()方法:​​​​​​​

package com.bezkoder.spring.thymeleaf.file.upload;

import javax.annotation.Resource;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import com.bezkoder.spring.thymeleaf.file.upload.service.FilesStorageService;

@SpringBootApplication
public class ThymeleafFileUploadApplication implements CommandLineRunner {

  @Resource
  FilesStorageService storageService;

  public static void main(String[] args) {
    SpringApplication.run(ThymeleafFileUploadApplication.class, args);
  }

  @Override
  public void run(String... arg) throws Exception {
//    storageService.deleteAll();
    storageService.init();
  }
}

运行 Spring 引导文件上传示例

使用以下命令运行 Spring 引导应用程序:mvn spring-boot:run

源代码

您可以在 Github 上找到本教程的完整源代码。

用于删除文件:
弹簧启动删除文件示例与百里香叶

结论

今天,我们已经学习了如何使用多部分文件创建Spring Boot Thymeleaf文件上传应用程序,并使用静态文件夹获取文件信息。

一次上传多个文件:
Spring 启动多个文件上传百里香叶

或带前端的全栈: – Angular + Spring Boot:文件上传示例 – React + Spring Boot:
文件上传示例

您还可以了解如何上传Excel / CSV文件并将内容存储在MySQL数据库中,并带有以下帖子: – Spring Boot:将Excel文件数据上传/导入MySQL数据库 – Spring Boot:将CSV文件数据上传/导入MySQL数据库
 

如果要像这样将文件存储在数据库中:

您可以在以下位置找到说明:
Spring 引导上传/下载文件到/从数据库示例

快乐学习!再见。

延伸阅读

– 弹簧启动上传图像并使用百里香叶显示 – 春季启动上传多个文件 休息 API
– 弹簧启动百里香叶 CRUD 示例
– 弹簧启动百里香叶分页和排序示例

异常处理:
– Spring Boot @ControllerAdvice & @ExceptionHandler 示例 – Spring Boot 中的@RestControllerAdvice示例

单元测试:
– JPA 存储库的弹簧引导单元测试
– 其余控制器的弹簧引导单元测试

部署:
– 在 AWS 上部署 Spring Boot 应用程序 – Elastic Beanstalk

关联:
– 带有 JPA 的 Spring Boot 一对一示例,Hibernate – 使用 JPA 的 Spring Boot One To More 示例,Hibernate – 使用 JPA 的 Spring Boot Many to Many 示例,Hibernate

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/68966.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

MongoDB的简介及安装配置

文章目录1、什么是MongoDB2、下载3、安装4、配置5、启动拓展&#xff08;mongo不是内部或外部命令&#xff09;1、什么是MongoDB MongoDB是一个基于分布式文件存储 [1] 的数据库。由C语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 MongoDB是一个介于关系数据…

Matlab基于KD树的离散点密度特征提取—点云处理及可视化第4期

在之前的文章中&#xff0c;分享了Matlab基于KD树的邻域点搜索方法&#xff1a; 在此基础上&#xff0c;进一步分享一下基于KD树的离散点密度特征提取方法。 先来看一下成品效果&#xff1a; 特别提示&#xff1a;《Matlab点云处理及可视化》系列文章整理自作者博士期间的部分…

汇编语言与微机原理 期末半开卷复习整理(下)

输入输出 8086采用I/O端口独立编址 in AL/AX,imm8/DX out imm8/DX,AL/AX 大于0FFH的端口只能存在DX 读外设(查询) status:in al,dxtest al,80H;//测标志位jz statusmov dx,100hin al,dx写外设&#xff08;查询&#xff09; status:mov dx,102Hin al,dxtest al,80Hjnz status…

Qt实现跨平台窗口选择功能

Qt实现跨平台获取鼠标位置窗口大小功能 文章目录Qt实现跨平台获取鼠标位置窗口大小功能1、概述2、实现效果3、实现原理4、关键代码5、源代码更多精彩内容&#x1f449;个人内容分类汇总 &#x1f448;&#x1f449;Qt自定义模块、工具&#x1f448; 1、概述 Qt版本&#xff1a…

从源码层面理解 React 是如何做 diff 的

大家好&#xff0c;我是前端西瓜哥。今天带带大家来分析 React 源码&#xff0c;理解它的单节点 diff 和多节点 diff 的具体实现。 React 的版本为 18.2.0 reconcileChildFibers React 的节点对比逻辑是在 reconcileChildFibers 方法中实现的。 reconcileChildFibers 是 Chil…

ATTCK-T1003-001-操作系统凭据转储:LSASS内存

0x01基础信息 具体信息详情ATT&CK编号T1003-001所属战术阶段凭据访问操作系统windows 7 旗舰版 SP1创建时间2022年11月17日监测平台火绒安全、火绒剑、sysmon 0x02技术原理 攻击者可能会尝试访问存储在本地安全机构子系统服务 (LSASS) 进程内存中的凭证材料。用户登录后&…

Linux文件服务配置FTP服务

作者简介&#xff1a;一名99年软件运维应届毕业生&#xff0c;正在自学云计算课程。宣言&#xff1a;人生就是B&#xff08;birth&#xff09;和D&#xff08;death&#xff09;之间的C&#xff08;choise&#xff09;&#xff0c;做好每一个选择。创作不易&#xff0c;动动小手…

【Python恶搞】Python实现祝福单身狗的恶搞项目,快@你的好朋友,祝福他吧 | 附源码

前言 halo&#xff0c;包子们上午好 咱就说&#xff0c;谁还没有一个单身的小伙伴呢 今天这个代码主要是为了祝福咱们单身的小伙伴 咱就说废话不多说&#xff0c;直接上才艺 相关文件 关注小编&#xff0c;私信小编领取哟&#xff01; 当然别忘了一件三连哟~~ 源码点击蓝色…

数据可视化是让信息表现更复杂?很多人可能错了

数据可视化&#xff0c;目前行业中很多人认识有些偏颇&#xff0c;数据可视化就是单纯认为是大屏展示、酷炫的图表&#xff0c;很多人仅仅是把数据可视化 作为展厅中的刚性需求而已&#xff0c;其实这个是对数据行业的偏见&#xff0c;很多人侧重于数据的表现&#xff0c;而非便…

谷歌北大扩散模型(Diffusion Model)首篇综述来了!

本综述&#xff08;Diffusion Models: A Comprehensive Survey of Methods and Applications&#xff09;来自加州大学&Google Research的Ming-Hsuan Yang、北京大学崔斌实验室以及CMU、UCLA、蒙特利尔Mila研究院等众研究团队&#xff0c;首次对现有的扩散生成模型&#xf…

ftp工具的21端口无法连上远程主机

一、检测是否有安装vsffpd netstat -tunlp 没有安装先安装 1.安装 vsftpd 执行以下命令&#xff0c;安装 vsftpd。 yum install vsftpd -y 2.启动服务 执行以下命令&#xff0c;启动服务。 systemctl start vsftpd 3.执行以下命令&#xff0c;确认服务是否启动。 netstat -tun…

【c++基础】第二章 微观部分:面向对象之类的组成

第二章 微观部分&#xff1a;面向对象之类的组成类函数构造函数析构函数拷贝构造函数运算符重载函数封装一个字符串类初始化列表this指针常对象和常成员函数&#xff08;方法&#xff09;静态属性和静态成员函数单例设计模式类 对象&#xff1a;属性和方法组成&#xff0c;是类…

Nature子刊 | 空间转录组技术及其发展方向

2022年10月《Nature Biotechnology》发表了一篇空间转录组&#xff08;ST&#xff09;技术的综述文章&#xff0c;详细描述了现有的ST技术及其发展方向。 检测生物分子的新技术一直是生物进步的关键驱动力。在检测生物分子时&#xff0c;研究人员在选择实验方法时一直面临着关键…

CENTOS上的网络安全工具(十四)搬到Docker上(2)?

既然说要搬到Docker上&#xff0c;那么肯定是要把咱日常习惯用的那些东西都往docker上堆一堆看的。我最先考虑的居然是SSH&#xff0c;乃至于到现在我都不知道我为什么第一个想到的是SSH——因为对虚拟机来说&#xff0c;首先考虑的当然是如何远程管理集群中的每个机器&#xf…

iptables用法总结

iptables 是集成在 Linux 内核中的包过滤防火墙系统。使用 iptables 可以添加、删除具体的过滤规则&#xff0c;iptables 默认维护着 4 个表和 5 个链&#xff0c;所有的防火墙策略规则都被分别写入这些表与链中。 1、iptables语法格式 iptables 命令的基本语法格式如下&…

C++ 基础笔记(入门到循环)

目录 1.认识C —— 初窥门径 一、C程序框架&#xff08;8分&#xff09; 二、语言规范&#xff08;16分&#xff09; 三、DEV-C软件&#xff08;下载链接&#xff09; 四、计算机快捷键 五、输入输出的应用 2.变量与赋值 —— 脚踏实地 2.1 变量类型 2.2 变量类型与变…

一文详解名字分类(字符级RNN)

目录 一.前言 二.数据预处理 三.构造神经网络 四.训练 五.评价结果&#xff08;预测&#xff09; 一.前言 我们将构建和训练字符级RNN来对单词进行分类。字符级RNN将单词作为一系列字符读取&#xff0c;在每一步输出预测和“隐藏状态”&#xff0c;将其先前的隐藏 状态输…

02-MySQL数据管理

目录 DDL&#xff08;数据操作语言&#xff09; 添加数据 添加student表数据 修改数据 WHERE条件子句 修改student表数据 删除数据 删除student表数据 总结&#xff1a; DDL&#xff08;数据操作语言&#xff09; 用于操作数据库对象中所包含的数据 关键字&#xff1…

STM32的光敏检测自动智能窗帘控制系统proteus设计

STM32的光敏检测自动智能窗帘控制系统proteus设计 ( proteus仿真程序演示视频&#xff09; 仿真图proteus 8.9 程序编译器&#xff1a;keil 5 编程语言&#xff1a;C语言 设计编号&#xff1a;C0074 主要功能&#xff1a; 结合实际情况&#xff0c;基于STM32单片机设计一…

ATTCK-T1078-001-默认账户

0x01基础信息 具体信息详情ATT&CK编号T1078-001所属战术阶段初始访问操作系统windows 7 旗舰版 SP1创建时间2022年11月10日监测平台火绒安全、火绒剑、sysmon 0x02技术原理 攻击者可能会获取和滥用默认帐户的凭据&#xff0c;以作为获得初始访问、持久性、特权升级或防御…