当前位置: 首页 > news >正文

资源操作:Resources

文章目录

  • 1. Spring Resources概述
    • 1.2 Resource 接口
    • 1.3 Resource的实现类
      • 1.3.1 UrlResource访问网络资源
      • 1.3.2 ClassPathResource访问类路径下资源
      • 1.3.3 FileSystemResource访问文件系统资源
      • 1.3.4 ServletContextResource
      • 1.3.5、InputStreamResource
      • 1.3.6、ByteArrayResource
    • 1.4 Resource类图
    • 1.5 ResourceLoader接口
      • 1.5.1. ResourceLoader概述
      • 1.5.2 使用演示
      • 1.5.3 ResoureceLoader总结
    • 1.6 ResourceLoaderAwore接口
    • 1.7 使用Resource作为属性
    • 1.8 应用程序上下文和资源路径
      • 1.8.1 概述
      • 1.8.2 ApplicationContext实现类指定访问策略
      • 1.8.3

1. Spring Resources概述

Java的标准java.net.URL类和各种URL前缀的标准处理程序无法满足所有对low-level资源的访问,比如:没有标准化的 URL 实现可用于访问需要从类路径或相对于 ServletContext 获取的资源。并且缺少某些Spring所需要的功能,例如检测某资源是否存在等。而Spring的Resource声明了访问low-level资源的能力

1.2 Resource 接口

Spring的Resource接口位于org.springframework.core.io中,旨在成为一个更强大的接口,用于抽象对低级资源的访问,以下显示了Resource接口定义的方法

public interface Resource extends InputStreamSource {boolean exists();boolean isReadable();boolean isOpen();boolean isFile();URL getURL() throws IOException;URI getURI() throws IOException;File getFile() throws IOException;ReadableByteChannel readableChannel() throws IOException;long contentLength() throws IOException;long lastModified() throws IOException;Resource createRelative(String relativePath) throws IOException;String getFilename();String getDescription();
}

Resource接口继承了InputStreamSource接口,提供了很多InputStreamSource并没有的方法,InputStreamSource接口,只有一个办法

 public interface InputStreamSource {InputStream getInputStream() throws IOException;}

其中一些重要的方法

  • getInputStream():找到并打开资源,返回一个InputStream以从资源中读取,预计每次调用都会返回一个新的InputStream(),调用者有责任关闭每个流
  • exists():返回一个布尔值,表明某个资源是否以物理形式存在
  • isOpen:返回一个布尔值,指示此资源是否具有开放流的句柄,如果为true,InputStream就不能够多次读取,只能读取一次并且及时关闭以避免内存泄漏 ,对于所有常规资源实现,返回false,但是InputStreamResource除外
  • getDescription():返回资源的描述,用来输出错误的日志,这通常是完全限定的文件名或资源的实现URL

其它方法

  • isReadable():表明资源的目录读取是否通过getInputStream()进行读取
  • isFile():表明这个资源是否代表一个文件系统的文件
  • getURL:返回一个URL句柄,如果资源不能够被及解析为URL,将抛出IOException
  • getURI():返回一个资源的句柄
  • getFile():返回某个文件,如果资源不能够被解析称为绝对路径,将会抛出FileNotFoundException
  • lastModified():资源最后一次修改的时间戳
  • createRelative():创建此资源的相关资源
  • getFilename:资源的文件名是什么

1.3 Resource的实现类

Resource 接口是 Spring 资源访问策略的抽象,它本身并不提供任何资源访问实现,具体的资源访问由该接口的实现类完成——每个实现类代表一种资源访问策略。Resource一般包括这些实现类:UrlResource、ClassPathResource、FileSystemResource、ServletContextResource、InputStreamResource、ByteArrayResource

1.3.1 UrlResource访问网络资源

Resource的一个实现类,用来访问网络资源它支持URL的绝对路径
Resource的一个实现类,用来访问网络资源,它支持URL的绝对路径。

http:------该前缀用于访问基于HTTP协议的网络资源。

ftp:------该前缀用于访问基于FTP协议的网络资源

file: ------该前缀用于从文件系统中读取资源

实验:访问基于HTTP协议的网络资源
创建一个maven子模块spring6-resources,配置Spring依赖(参考前面)

package com.gdhd.spring6.resources;import org.springframework.core.io.UrlResource;public class UrlResourceDemo {public static void loadAndReadUrlResource(String path){// 创建一个 Resource 对象UrlResource url = null;try {url = new UrlResource(path);// 获取资源名System.out.println(url.getFilename());System.out.println(url.getURI());// 获取资源描述System.out.println(url.getDescription());//获取资源内容System.out.println(url.getInputStream().read());} catch (Exception e) {throw new RuntimeException(e);}}public static void main(String[] args) {//访问网络资源loadAndReadUrlResource("http://www.baidu.com");}
}

实验二:在项目根路径下创建文件,从文件系统中读取资源

public static void main(String[] args) {//1 访问网络资源//loadAndReadUrlResource("http://www.gdhd.com");//2 访问文件系统资源loadAndReadUrlResource("file:gdhd.txt");
}

1.3.2 ClassPathResource访问类路径下资源

ClassPathResource用来访问类加载路径下的资源,相对于其他的Resource实现类,其主要优势是方便访问类路径里的资源,尤其对于Web应用,ClassPathResource可自动搜索位于classes下的资源文件,无需使用绝对路径访问
在类路径下创建文件gdhd.txt,使用ClassPathResource 访问
在这里插入图片描述

package com.gdhd.spring6.resources;import org.springframework.core.io.ClassPathResource;
import java.io.InputStream;public class ClassPathResourceDemo {public static void loadAndReadUrlResource(String path) throws Exception{// 创建一个 Resource 对象ClassPathResource resource = new ClassPathResource(path);// 获取文件名System.out.println("resource.getFileName = " + resource.getFilename());// 获取文件描述System.out.println("resource.getDescription = "+ resource.getDescription());//获取文件内容InputStream in = resource.getInputStream();byte[] b = new byte[1024];while(in.read(b)!=-1) {System.out.println(new String(b));}}public static void main(String[] args) throws Exception {loadAndReadUrlResource("gdhd.txt");}
}

ClassPathResource实例可使用ClassPathResource构造器显式地创建,但更多的时候它都是隐式地创建的。当执行Spring的某个方法时,该方法接受一个代表资源路径的字符串参数,当Spring识别该字符串参数中包含classpath:前缀后,系统会自动创建ClassPathResource对象。

1.3.3 FileSystemResource访问文件系统资源

Spring提供FileSystemResource 类用于访问文件系统资源,使用 FileSystemResource 来访问文件系统资源并没有太大的优势,因为 Java 提供的 File 类也可用于访问文件系统资源。

package com.gdhd.spring6.resources;import org.springframework.core.io.FileSystemResource;import java.io.InputStream;public class FileSystemResourceDemo {public static void loadAndReadUrlResource(String path) throws Exception{//相对路径FileSystemResource resource = new FileSystemResource("gdhd.txt");//绝对路径//FileSystemResource resource = new FileSystemResource("C:\\atguigu.txt");// 获取文件名System.out.println("resource.getFileName = " + resource.getFilename());// 获取文件描述System.out.println("resource.getDescription = "+ resource.getDescription());//获取文件内容InputStream in = resource.getInputStream();byte[] b = new byte[1024];while(in.read(b)!=-1) {System.out.println(new String(b));}}public static void main(String[] args) throws Exception {loadAndReadUrlResource("gdhd.txt");}
}

FileSystemResource实例可使用FileSystemResource构造器显示地创建,但更多的时候它都是隐式创建。执行Spring的某个方法时,该方法接受一个代表资源路径的字符串参数,当Spring识别该字符串参数中包含file:前缀后,系统将会自动创建FileSyste

1.3.4 ServletContextResource

这是ServletContext资源的Resource实现,它解释相关Web应用程序根目录中的相对路径。它始终支持流(stream)访问和URL访问,但只有在扩展Web应用程序存档且资源实际位于文件系统上时才允许java.io.File访问。无论它是在文件系统上扩展还是直接从JAR或其他地方(如数据库)访问,实际上都依赖于Servlet容器。

1.3.5、InputStreamResource

InputStreamResource 是给定的输入流(InputStream)的Resource实现。它的使用场景在没有特定的资源实现的时候使用(感觉和@Component 的适用场景很相似)。与其他Resource实现相比,这是已打开资源的描述符。 因此,它的isOpen()方法返回true。如果需要将资源描述符保留在某处或者需要多次读取流,请不要使用它。

1.3.6、ByteArrayResource

字节数组的Resource实现类。通过给定的数组创建了一个ByteArrayInputStream。它对于从任何给定的字节数组加载内容非常有用,而无需求助于单次使用的InputStreamResource。

1.4 Resource类图

上述Resource实现类与Resource顶级接口之间的关系可以用下面的UML关系模型来表示

在这里插入图片描述

1.5 ResourceLoader接口

1.5.1. ResourceLoader概述

Spring 提供如下两个标志性接口:

(1)ResourceLoader : 该接口实现类的实例可以获得一个Resource实例。
2) ResourceLoaderAware : 该接口实现类的实例将获得一个ResourceLoader的引用。
在ResourceLoader接口里有如下方法:
1)Resource getResource(String location) : 该接口仅有这个方法,用于返回一个Resource实例。ApplicationContext实现类都实现ResourceLoader接口,因此ApplicationContext可直接获取Resource实例。

1.5.2 使用演示

实验一:ClassPathXmlApplicationContext获取Resource实例

package com.gdhd.spring6.resouceloader;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;public class Demo1 {public static void main(String[] args) {ApplicationContext ctx = new ClassPathXmlApplicationContext();
//        通过ApplicationContext访问资源
//        ApplicationContext实例获取Resource实例时,
//        默认采用与ApplicationContext相同的资源访问策略Resource res = ctx.getResource("gdhd.txt");System.out.println(res.getFilename());}
}

实验二:FileSystemApplicationContext获取Resource实

package com.gdhd.spring6.resouceloader;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.Resource;public class Demo2 {public static void main(String[] args) {ApplicationContext ctx = new FileSystemXmlApplicationContext();Resource res = ctx.getResource("gdhd.txt");System.out.println(res.getFilename());}
}

1.5.3 ResoureceLoader总结

Spring将采用和ApplicationContext相同的策略来访问资源。也就是说,如果ApplicationContext是FileSystemXmlApplicationContext,res就是FileSystemResource实例;如果ApplicationContext是ClassPathXmlApplicationContext,res就是ClassPathResource实例

当Spring应用需要进行资源访问时,实际上并不需要直接使用Resource实现类,而是调用ResourceLoader实例的getResource()方法来获得资源,ReosurceLoader将会负责选择Reosurce实现类,也就是确定具体的资源访问策略,从而将应用程序和具体的资源访问策略分离开来

另外,使用ApplicationContext访问资源时,可通过不同前缀指定强制使用指定的ClassPathResource、FileSystemResource等实现类

Resource res = ctx.getResource("calsspath:bean.xml");
Resrouce res = ctx.getResource("file:bean.xml");
Resource res = ctx.getResource("http://localhost:8080/beans.xml");

1.6 ResourceLoaderAwore接口

ResourceLoaderAware接口实现类的实例将获得一个ResourceLoader的引用,ResourceLoaderAware接口也提供了一个setResourceLoader()方法,该方法将由Spring容器负责调用,Spring容器会将一个ResourceLoader对象作为该方法的参数传入。

如果把实现ResourceLoaderAware接口的Bean类部署在Spring容器中,Spring容器会将自身当成ResourceLoader作为setResourceLoader()方法的参数传入。由于ApplicationContext的实现类都实现了ResourceLoader接口,Spring容器自身完全可作为ResorceLoader使用。
实验:演示ResourceLoaderAware使用

第一步 创建类,实现ResourceLoaderAware接口

package com.gdhd.spring6.resouceloader;import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.ResourceLoader;public class TestBean implements ResourceLoaderAware {private ResourceLoader resourceLoader;//实现ResourceLoaderAware接口必须实现的方法//如果把该Bean部署在Spring容器中,该方法将会有Spring容器负责调用。//SPring容器调用该方法时,Spring会将自身作为参数传给该方法。public void setResourceLoader(ResourceLoader resourceLoader) {this.resourceLoader = resourceLoader;}//返回ResourceLoader对象的应用public ResourceLoader getResourceLoader(){return this.resourceLoader;}}

第二步 创建bean.xml文件,配置TestBea

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="testBean" class="com.gdhd.spring6.resouceloader.TestBean"></bean>
</beans>

第三步 测试

package com.atguigu.spring6.resouceloader;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;public class Demo3 {public static void main(String[] args) {//Spring容器会将一个ResourceLoader对象作为该方法的参数传入ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml");TestBean testBean = ctx.getBean("testBean",TestBean.class);//获取ResourceLoader对象ResourceLoader resourceLoader = testBean.getResourceLoader();System.out.println("Spring容器将自身注入到ResourceLoaderAware Bean 中 ? :" + (resourceLoader == ctx));//加载其他资源Resource resource = resourceLoader.getResource("atguigu.txt");System.out.println(resource.getFilename());System.out.println(resource.getDescription());}
}

1.7 使用Resource作为属性

前面介绍了 Spring 提供的资源访问策略,但这些依赖访问策略要么需要使用 Resource 实现类,要么需要使用 ApplicationContext 来获取资源。实际上,当应用程序中的 Bean 实例需要访问资源时,Spring 有更好的解决方法:直接利用依赖注入。从这个意义上来看,Spring 框架不仅充分利用了策略模式来简化资源访问,而且还将策略模式和 IoC 进行充分地结合,最大程度地简化了 Spring 资源访问。

归纳起来,如果 Bean 实例需要访问资源,有如下两种解决方案:

  • 代码中获取 Resource 实例。
  • 使用依赖注入。

对于第一种方式,当程序获取 Resource 实例时,总需要提供 Resource 所在的位置,不管通过 FileSystemResource 创建实例,还是通过 ClassPathResource 创建实例,或者通过 ApplicationContext 的 getResource() 方法获取实例,都需要提供资源位置。这意味着:资源所在的物理位置将被耦合到代码中,如果资源位置发生改变,则必须改写程序。因此,通常建议采用第二种方法,让 Spring 为 Bean 实例依赖注入资源。

实验:让Spring为Bean实例依赖注入资源

第一步 创建依赖注入类,定义属性和方法

package com.gdhd.spring6.resouceloader;import org.springframework.core.io.Resource;public class ResourceBean {private Resource res;public void setRes(Resource res) {this.res = res;}public Resource getRes() {return res;}public void parse(){System.out.println(res.getFilename());System.out.println(res.getDescription());}
}

第二步 创建spring配置文件,配置依赖注入

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="resourceBean" class="com.gdhd.spring6.resouceloader.ResourceBean" ><!-- 可以使用file:、http:、ftp:等前缀强制Spring采用对应的资源访问策略 --><!-- 如果不采用任何前缀,则Spring将采用与该ApplicationContext相同的资源访问策略来访问资源 --><property name="res" value="classpath:atguigu.txt"/></bean>
</beans>

第三步 测试

package com.atguigu.spring6.resouceloader;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class Demo4 {public static void main(String[] args) {ApplicationContext ctx =new ClassPathXmlApplicationContext("bean.xml");ResourceBean resourceBean = ctx.getBean("resourceBean",ResourceBean.class);resourceBean.parse();}
}

1.8 应用程序上下文和资源路径

1.8.1 概述

不管以怎样的方式创建ApplicationContext实例,都需要为ApplicationContext指定配置文件,Spring允许使用一份或多分XML配置文件。当程序创建ApplicationContext实例时,通常也是以Resource的方式来访问配置文件的,所以ApplicationContext完全支持ClassPathResource、FileSystemResource、ServletContextResource等资源访问方式。

ApplicationContext确定资源访问策略通常有两种方法:

(1)使用ApplicationContext实现类指定访问策略。

(2)使用前缀指定访问策略。

1.8.2 ApplicationContext实现类指定访问策略

创建ApplicationContext对象时,通常可以使用如下实现类:

(1) ClassPathXMLApplicationContext : 对应使用ClassPathResource进行资源访问。

(2)FileSystemXmlApplicationContext : 对应使用FileSystemResource进行资源访问。

(3)XmlWebApplicationContext : 对应使用ServletContextResource进行资源访问。

当使用ApplicationContext的不同实现类时,就意味着Spring使用响应的资源访问策略。

效果前面已经演示

1.8.3

实验一:classpath前缀使用

package com.gdhd.spring6.context;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.Resource;public class Demo1 {public static void main(String[] args) {/** 通过搜索文件系统路径下的xml文件创建ApplicationContext,* 但通过指定classpath:前缀强制搜索类加载路径* classpath:bean.xml* */ApplicationContext ctx =new ClassPathXmlApplicationContext("classpath:bean.xml");System.out.println(ctx);Resource resource = ctx.getResource("gdhd.txt");System.out.println(resource.getFilename());System.out.println(resource.getDescription());}
}

实验二:classpath通配符使用

classpath * :前缀提供了加载多个XML配置文件的能力,当使用classpath*:前缀来指定XML配置文件时,系统将搜索类加载路径,找到所有与文件名匹配的文件,分别加载文件中的配置定义,最后合并成一个ApplicationContext。

    ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath*:bean.xml");System.out.println(ctx);

当使用classpath * :前缀时,Spring将会搜索类加载路径下所有满足该规则的配置文件。

如果不是采用classpath * :前缀,而是改为使用classpath:前缀,Spring则只加载第一个符合条件的XML文件

注意 :

classpath * : 前缀仅对ApplicationContext有效。实际情况是,创建ApplicationContext时,分别访问多个配置文件(通过ClassLoader的getResource方法实现)。因此,classpath * :前缀不可用于Resource。
使用三:通配符其他使用

一次性加载多个配置文件的方式:指定配置文件时使用通配符

    ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:bean*.xml");

Spring允许将classpath*:前缀和通配符结合使用:

    ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath*:bean*.xml");

相关文章:

资源操作:Resources

文章目录1. Spring Resources概述1.2 Resource 接口1.3 Resource的实现类1.3.1 UrlResource访问网络资源1.3.2 ClassPathResource访问类路径下资源1.3.3 FileSystemResource访问文件系统资源1.3.4 ServletContextResource1.3.5、InputStreamResource1.3.6、ByteArrayResource1.…...

GDB调试的学习

很早就想在好好学一学gdb了&#xff0c;正好最近学算法&#xff08;以前一直以为干硬件不需要什么特别厉害的算法&#xff0c;结果现在卷起来了。大厂面试题也有复杂一些的算法了&#xff09; 下面的这些命令是别的博主总结的 GDB 调试过程_gdb调试过程_麷飞花的博客-CSDN博客…...

熵值法综合评价分析流程

熵值法综合评价分析流程 一、案例背景 当前有一份数据&#xff0c;是各品牌车各个维度的得分情况&#xff0c;现在想要使用熵值法进行综合评价&#xff0c;得到各品牌车的综合得分&#xff0c;从而进行车型优劣对比&#xff0c;为消费者提供购车依据。 数据如下&#xff08;数…...

使用Python Pandas库操作Excel表格的技巧

在数据分析和处理中&#xff0c;我们经常需要对Excel表格进行操作。Python Pandas库提供了丰富的API来读取、写入、修改Excel表格。本文将介绍如何使用Python Pandas库操作Excel表格&#xff0c;包括向Excel表格添加新行、创建Excel表格等。 1.向Excel表格添加新行 下面是一个…...

LeetCode练习七:动态规划上:线性动态规划

文章目录一、 动态规划基础知识1.1 动态规划简介1.2 动态规划的特征1.2.1 最优子结构性质1.2.2 重叠子问题性质1.2.3 无后效性1.3 动态规划的基本思路1.4 动态规划基础应用1.4.1 斐波那契数1.4.2 爬楼梯1.4.3 不同路径1.5 个人总结二、记忆化搜索2.1 记忆化搜索简介2.2 记忆化搜…...

基于正点原子F407开发版和SPI接口屏移植touchgfx完整教程(一)

一、相关软件包安装 1、打开cubemx包管理器 2、安装F4软件包 3、安装touchgfx软件包 二、工程配置 1、新建工程 2、sys配置 3、rcc配置 4、crc配置 5、添加touchgfx软件包 6、配置touchgfx软件包 将width和height改为自己屏幕尺寸 7、生成工程 三、代码修改 1、将屏幕相关驱…...

Linux--进程间通信

前言 上一篇相关Linux文章已经时隔2月&#xff0c;Linux的学习也相对于来说是更加苦涩&#xff1b;无妨&#xff0c;漫漫其修远兮,吾将上下而求索。 下面该片文章主要是对进程间通信进行介绍&#xff0c;还对管道&#xff0c;消息队列&#xff0c;共享内存&#xff0c;信号量都…...

hadoop伪分布式集群搭建

基于hadoop 3.1.4 一、准备好需要的文件 1、hadoop-3.1.4编译完成的包 链接: https://pan.baidu.com/s/1tKLDTRcwSnAptjhKZiwAKg 提取码: ekvc 2、需要jdk环境 链接: https://pan.baidu.com/s/18JtAWbVcamd2J_oIeSVzKw 提取码: bmny 3、vmware安装包 链接: https://pan.baidu…...

Qt 中的信息输出机制:QDebug、QInfo、QWarning、QCritical 的简单介绍和用法

Qt 中的信息输出机制介绍QDebug在 Qt 中使用 qDebug输出不同类型的信息浮点数&#xff1a;使用 %!f(MISSING) 格式化符号输出浮点数布尔值&#xff1a;使用 %! (MISSING)和 %! (MISSING)格式化符号输出布尔值对象&#xff1a;使用 qPrintable() 函数输出对象的信息qInfoqWarnin…...

C++读写excel文件的的第三方库

一、比较流行的库 1. OpenXLSX 用于读取、写入、创建和修改 Microsoft Excel (.xlsx) 文件的 C 库。 2. xlnt xlnt 是一个现代 C 库&#xff0c;用于操作内存中的电子表格以及从 XLSX 文件读取/写入它们&#xff0c;如ECMA 376 第 4 版中所述。xlnt 1.0 版的首次公开发布是在 …...

【关于Linux中----多线程(一)】

文章目录认识线程创建线程线程优点和缺点创建一批线程终止线程线程的等待问题认识线程 在一个程序里的一个执行路线就叫做线程&#xff08;thread&#xff09;。更准确的定义是&#xff1a;线程是“一个进程内部的控制序列”一切进程至少都有一个执行线程线程在进程内部运行&a…...

2023年全国最新安全员精选真题及答案34

百分百题库提供安全员考试试题、建筑安全员考试预测题、建筑安全员ABC考试真题、安全员证考试题库等&#xff0c;提供在线做题刷题&#xff0c;在线模拟考试&#xff0c;助你考试轻松过关。 11.&#xff08;单选题&#xff09;物料提升机附墙架设置要符合设计要求&#xff0c;但…...

数据出境是什么意思?我国数据出境合规要求是什么?

随着经济全球化深入以及云计算等技术的发展&#xff0c;数据在全球范围跨境流动。数据跨境在促进经济增长、加速创新的同时&#xff0c;对数据主权、数据权属、个人信息保护等一系列问题逐渐浮出水面。今天我们就先来了解一下数据出境是什么意思&#xff1f;我国数据出境合规要…...

Liunx——Git工具使用

目录 1&#xff09;使用 git 命令行安装 git 2&#xff09;在 Gitee 创建仓库 创建仓库 3&#xff09;Linux克隆仓库到本地 4&#xff09;提交代码三板斧&#xff1a; 1.三板斧第一招: git add 2.三板斧第二招: git commit 3.三板斧第三招: git push 5&#xff09;所遇…...

微软语音合成工具+基于Electron + Vue + ElementPlus + Vite 构建并能将文字转换为语音 MP3

微软语音合成工具基于Electron Vue ElementPlus Vite 构建并能将文字转换为语音 MP3 资源下&#xff1a;微软语音合成工具基于ElectronVueElementPlusVite构建并能将文字转换为语音MP3资源-CSDN文库 本文将介绍如何使用微软语音合成工具和前端技术栈进行开发&#xff0c;…...

Mongodb学习笔记2

文章目录前言一、搭建项目二、开始编写java代码1. 新增2.查询3. 修改4. 删除5.根据条件查询6. 关联查询7. 索引相关总结前言 MongoTemplate 相关操作 CRUD,聚合查询等; 一、搭建项目 springboot项目创建引入mongo 依赖docker 安装好mongo数据库配置yml 链接mongo spring:dat…...

学习Tensorflow之基本操作

学习Tensorflow之基本操作Tensorflow基本操作1. 创建张量(1) 创建标量(2) 创建向量(3) 创建矩阵(4) shape属性(5) 判别张量类型(6) 列表和ndarray转张量2. 创建特殊张量(1) tf.ones与tf.ones_like(2) tf.zeros与tf.zeros_like(3) tf.fill(3) tf.random.normal(4) tf.random.uni…...

《Spring系列》第2章 解析XML获取Bean

一、基础代码 Spring加载bean实例的代码 public static void main(String[] args) throws IOException {// 1.获取资源Resource resource new ClassPathResource("bean.xml");// 2.获取BeanFactoryDefaultListableBeanFactory factory new DefaultListableBeanFa…...

小红书20230326暑假实习笔试

第一题&#xff1a;加密 小明学会了一种加密方式。他定义suc(x)为x在字母表中的后继&#xff0c;例如a的后继为b&#xff0c;b的后继为c… &#xff08;即按字母表的顺序后一个&#xff09;。特别的&#xff0c;z的后继为a。对于一个原字符串S&#xff0c;将其中每个字母x都替…...

【java】不要二、把字符串转成整数

目录 &#x1f525;一、编程题 1.不要二 2.把字符串转换成整数 &#x1f525;一、编程题 1.不要二 链接&#xff1a;不要二_牛客题霸_牛客网 (nowcoder.com) 描述&#xff1a;二货小易有一个W*H的网格盒子&#xff0c;网格的行编号为0~H-1&#xff0c;网格的列编号为0~W-1…...

数据的质量管控工作

数据的质量管控工作&#xff0c;整个工作应该围绕启动阶段制定的目标进行。适当引入一些质量管控工具可帮助我们更高效的完成工作。 第一步、数据剖析 首先应该进行已知数据问题的评估&#xff0c;这里评估的范围也应控制本轮管控的目标范围内。其次&#xff0c;通过对数据进行…...

【SpringBoot笔记29】SpringBoot集成RabbitMQ消息队列

这篇文章,主要介绍SpringBoot如何集成RabbitMQ消息队列。 目录 一、集成RabbitMQ 1.1、引入amqp依赖 1.2、添加连接信息 1.3、添加RabbitMQ配置类...

前端架构师-week2-脚手架架构设计和框架搭建

将收获什么 脚手架的实现原理 Lerna的常见用法 架构设计技巧和架构图绘制方法 主要内容 学习如何以架构师的角度思考基础架构问题 多 Package 项目管理痛点和解决方案&#xff0c;基于 Lerna 脚手架框架搭建 imooc-cli 脚手架需求分析和架构设计&#xff0c;架构设计图 附赠内…...

CMake项目实战指令详细分析

CMake是一个跨平台的自动化构建系统&#xff0c;可以用简单的语句来描述所有平台的编译过程。CMake可以输出各种各样的编译文件&#xff0c;如Makefile、VisualStudio等。 CMake主要是编写CMakeLists.txt文件&#xff0c;然后用cmake命令将CMakeLists.txt文件转化为make所需要的…...

【深度学习】——LSTM参数设置

批大小设置 LSTM的批大小可以根据训练数据集的大小和计算资源的限制来确定。一般而言&#xff0c;批大小越大&#xff0c;训练速度越快&#xff0c;但可能会导致过拟合和内存限制。批大小越小&#xff0c;训练速度越慢&#xff0c;但对于较大的数据集和内存限制较严格的情况下…...

计算机网络高频60问 背完差不多了!!

计算机网络高频60问 网络分层结构 计算机网络体系大致分为三种&#xff0c;OSI七层模型、TCP/IP四层模型和五层模型。一般面试的时候考察比较多的是五层模型。 五层模型&#xff1a;应用层、传输层、网络层、数据链路层、物理层。 应用层&#xff1a;为应用程序提供交互服务…...

路由策略小实验

实验要求&#xff1a; 1、R1环回使用重发布&#xff0c;R2和R3使用双向重发布 2、使用路由策略解决&#xff0c;选路不佳 第一步&#xff0c;基础配置 [R1]int l0 [R1-LoopBack0]ip add 1.1.1.1 24 [R1-LoopBack0]int g0/0/0 [R1-GigabitEthernet0/0/0]ip add 192.168.12.1 …...

C语言realloc背后的内存管理

malloc申请内存&#xff0c;但不初始化。 calloc申请内存&#xff0c;且初始化为0。 free释放内存。 realloc重新分配已经分配的内存空间&#xff0c;可以变小&#xff0c;也可以变大。 以前一直有一个疑问&#xff0c;realloc是不是经常失败&#xff1f; 其实&#xff0c;rea…...

GPT可以被放任的在问答区应用吗?

GPT可以被放任的在问答区应用吗&#xff1f;1、CSDN问答乱象2、GPT-4&#xff0c;大增长时代的序幕数字生命离我们到底还有多远&#xff1f;AI 家教/老师/教育 距离独立又有哪些需要完成的过程&#xff1f;3、老顾对CSDN问答的一些看法老顾对GPT使用者的一些建议1、CSDN问答乱象…...

限制网络接口的一些简介(一)

大家在上网的时候&#xff0c;我们设置了www&#xff0c;当有来自internet的www要求时&#xff0c;我们的主机就会予以响应。这是因为你的主机已经开启了www的监听端口。所以&#xff0c;当我们启用一个daemon时&#xff0c;就可能触发主机的端口进行监听的动作&#xff0c;此时…...