spring注解驱动开发(一)

Spring常用注解(绝对经典)

1、需要导入的spring框架的依赖

    <dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.3.12.RELEASE</version></dependency>

2、@Configuration

设置类为配置类

3、AnnotationConfigApplicationContext

  • 通过配置类获取上下文环境applicationContext
  • 可以通过getBeanDefinitionNames()获得配置类中配置的各类Bean
  • 也可以使用getBeanNamesForType()通过类型来获得bean的name(id)
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();for (String str : beanDefinitionNames) {System.out.println(str);}

4、@Bean

  • 注册一个javaBean
  • 默认用方法名作为Bean的id
  • 使用AnnotationConfigApplicationContext的实例 通过getBean来获得这个Bean
@Configuration
@ComponentScan(value = "com.atguigu")
public class MainConfig {@Beanpublic Person person(){return new Person("lisi",20);}
}
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);Person bean = applicationContext.getBean(Person.class);System.out.println(bean);

5、@ComponentScan

为配置类开启组件扫描

  • 放在配置类的上方,指定扫描的包路径如
@ComponentScan(value = "com.atguigu")
  • 还可以使用excludeFilter来设置类扫描规则如包含、排除,excludeFilter需要设置为一个数组
    排除
    包含使用excludeFilter,并为其设置一个过滤数组,来指定需要过滤掉那些组件
@Configuration
@ComponentScan(value = "com.atguigu",excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,classes ={Controller.class,Service.class} )
})
public class MainConfig {@Beanpublic Person person(){return new Person("lisi",20);}
}

包含
包含使用includeFilter,包含里面需要设置使用默认规则为false

@Configuration
@ComponentScan(value = "com.atguigu",includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,classes ={Controller.class,Service.class} )},useDefaultFilters = false)
public class MainConfig {@Beanpublic Person person(){return new Person("lisi",20);}
}

还可以设置按给定类型过滤

@Configuration
@ComponentScan(value = "com.atguigu",includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,classes ={Controller.class,Service.class}),@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,classes ={BookService.class})
},useDefaultFilters = false)
public class MainConfig {@Beanpublic Person person(){return new Person("lisi",20);}
}

其他可以设置的过滤方式还可以有:

  • 使用FilterType.ASPECTJ按照ASPECTJ表达式
  • 使用FilterType.REGEX按照REGEX正则表达式
  • 使用FilterType.CUSTOM按照自定义规则过滤(需要实现TypeFilter接口)

自定义过滤规则

public class MyTypeFilter implements TypeFilter {/*metadataReader:读取到的当前正在扫描的类的信息metadataReaderFactory:可以获取到其他任何类的信息*/@Overridepublic boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {//获取当前类的注解信息AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();//获取当前正在扫描的类的类信息ClassMetadata classMetadata = metadataReader.getClassMetadata();//获取当前类的资源(类的路径)Resource resource = metadataReader.getResource();String className = classMetadata.getClassName();System.out.println(resource);System.out.println(className);if(className.contains("er")){return true;}return false;}
}

设置自定义规则

@Configuration
@ComponentScan(value = "com.atguigu",includeFilters = {@ComponentScan.Filter(type = FilterType.CUSTOM,classes = {MyTypeFilter.class})
},useDefaultFilters = false)
public class MainConfig {@Beanpublic Person person(){return new Person("lisi",20);}
}

测试代码

@Testpublic void testbeans() {AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();for (String str : beanDefinitionNames) {System.out.println(str);}}

测试结果

测试规则打印内容

file [/Users/human/Desktop/Project/05SpringMVC/spring-annotation/target/classes/com/atguigu/bean/Person.class]
com.atguigu.bean.Person
file [/Users/human/Desktop/Project/05SpringMVC/spring-annotation/target/classes/com/atguigu/config/MyTypeFilter.class]
com.atguigu.config.MyTypeFilter
file [/Users/human/Desktop/Project/05SpringMVC/spring-annotation/target/classes/com/atguigu/controller/BookController.class]
com.atguigu.controller.BookController
file [/Users/human/Desktop/Project/05SpringMVC/spring-annotation/target/classes/com/atguigu/dao/BookDAO.class]
com.atguigu.dao.BookDAO
file [/Users/human/Desktop/Project/05SpringMVC/spring-annotation/target/classes/com/atguigu/service/BookService.class]
com.atguigu.service.BookService
file [/Users/human/Desktop/Project/05SpringMVC/spring-annotation/target/classes/com/atguigu/test/MainTest.class]
com.atguigu.test.MainTest

测试类打印过滤结果

org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
mainConfig
person
myTypeFilter
bookController
bookService

6、@Controller

将类配置为Controller类

7、@Service

将类配置为service类

8、@Repository

将类配置为dao操作的类

9、@Component

将类配置为通用类组件

10、@Scope

调整bean的作用域范围,默认单实例,可以修改为多实例
Bean是默认单实例的,通过指明prototype(多实例)和singleton(单实例)属性指明是否单实例

  • prototype:多实例
  • singleton:单实例
  • request:同一次请求创建一个实例
  • session:同一个session创建一个实例
@Configuration
@ComponentScan(value = "com.atguigu")
public class MainConfig {//Bean是默认单实例的,通过指明prototype(多实例)和singleton(单实例)属性指明是是否单实例//prototype:多实例//singleton:单实例//request:同一次请求创建一个实例//session:同一个session创建一个实例@Scope("prototype")@Bean("person")//指定bean的自定义idpublic Person person(){return new Person("张三",20);}
}

测试

  @Testpublic void testbeans() {AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);Object bean1 = applicationContext.getBean("person");Object bean2 = applicationContext.getBean("person");System.out.println(bean1==bean2);}

测试结果为false

11、@Lazy懒加载

实例默认在容器创建时立即加载
使用@Lazy后,当需要创建实例时才被加载

  • 不使用懒加载
    实体类构造函数
  public Person(String name, Integer age) {System.out.println("给容器添加Person对象");this.name = name;this.age = age;}

测试代码

@Testpublic void testbeans() {AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);System.out.println("容器已创建完成");//没有获取类的代码,单实际上类的实例已经被加载进容器了}

测试结果

给容器添加Person对象
容器已创建完成
  • 使用懒加载
@Configuration
@ComponentScan(value = "com.atguigu")
public class MainConfig {
//  @Scope("prototype")@Lazy@Bean("person")//指定bean的自定义idpublic Person person(){return new Person("张三",20);}
}

测试代码

@Testpublic void testbeans() {AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);System.out.println("容器已创建完成");Object bean1 = applicationContext.getBean("person");//这一句出现后才加载Person类}

测试结果

给容器添加Person对象
容器已创建完成

12、@Conditional

  • 按一定条件注册bean,满足条件就给容器注册bean,否则不注入
  • 要作为自定义条件,需要创建自定义condition类,并要实现Condition接口,并实现match方法
  • conditional不仅可以标在方法上,还可以标记在类上
//判断是否是Linux系统的条件
//要作为自定义条件,要实现Condition接口,并实现match方法
//AnnotatedTypeMetadata:注释信息
public class LinuxCondition implements Condition {@Overridepublic boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {//判断linux洗洗ConfigurableListableBeanFactory beanFactory = conditionContext.getBeanFactory();//获取类加载器ClassLoader classLoader = conditionContext.getClassLoader();//获得当前环境信息Environment environment = conditionContext.getEnvironment();//获取到bean定义的注册类BeanDefinitionRegistry registry = conditionContext.getRegistry();String OSproperty = environment.getProperty("os.name");if (OSproperty.contains("Mac OS X")){return true;}return false;}
}

另一个自定义条件

public class WindowsCondition implements Condition {@Overridepublic boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {Environment environment = conditionContext.getEnvironment();//获取操作系统信息String OSproperty = environment.getProperty("os.name");if (OSproperty.contains("Window")){return true;}return false;}
}

配置类信息


@Configuration
@ComponentScan(value = "com.atguigu")
public class MainConfig {
//  @Scope("prototype")@Lazy@Bean("person")//指定bean的自定义idpublic Person person(){return new Person("张三",20);}@Conditional({WindowsCondition.class})@Bean("male")public Person personMale(){return new Person("lisi",33);}@Conditional({LinuxCondition.class})@Bean("female")public Person personFemale(){return new Person("wanger",23);}
}

测试类信息

@Testpublic void testBeans() {AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);//获取ioc容器的运行环境ConfigurableEnvironment environment=applicationContext.getEnvironment();//获取操作系统名称String property = environment.getProperty("os.name");System.out.println(property);String[] namesForType = applicationContext.getBeanNamesForType(Person.class);for (String name:namesForType) {System.out.println(name);}}

测试结果

Mac OS X
person
female

13、给IOC容器中注册组件的5种方法

  1. 包扫描+组件类上标注注解:(@Controller,@Service,@Repository,@Component)
  2. @Bean:导入第三方包的组件
  3. @Import:快速给容器导入一个组件
    1)@Import(要导入到容器的组件),容器中就会自动注册这个逐渐,id默认是全类名
    2)ImportSelector:返回需要导入的组件的全类名数组

4.使用ImportBeanDefinitionRegistrar
5.使用Spring提供的FactoryBean(工厂bean)注册组件
1)默认获得的是工厂bean调用getObject创建的对象
2)要获取工厂bean本身,需要给id前面加一个&标识

14、@Import 快速导入一个类

使用@Import快速为配置类导入一个bean类
可以同时导入多个bean类
需要再配置类上方书写

  • 创建被导入的bean类
public class Color {
}
public class Red {
}
  • 给配置类导入该类
@Configuration
@ComponentScan(value = "com.atguigu")
@Import({Color.class, Red.class})//在这里进行快速地导入,可以是数组形式
public class MainConfig {
//  @Scope("prototype")@Lazy@Bean("person")//指定bean的自定义idpublic Person person(){return new Person("张三",20);}@Conditional({WindowsCondition.class})@Bean("male")public Person personMale(){return new Person("lisi",33);}@Conditional({LinuxCondition.class})@Bean("female")public Person personFemale(){return new Person("wanger",23);}
}

测试类代码

 AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);@Testpublic void testImport(){printBeans(applicationContext);}private void printBeans(AnnotationConfigApplicationContext applicationContext){String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();for (String name:beanDefinitionNames) {System.out.println(name);}}

测试结果

org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
mainConfig
bookController
bookDAO
bookService
com.atguigu.bean.Color
com.atguigu.bean.Red
person
female

15、ImportSelector接口导入一个类

  • ImportSelector:返回需要导入的组件的全类名数组
  • 需要实现ImportSelector接口并改写selectImports方法

创建需要被导入的类

public class Blue {
}
public class Yellow {
}

创建自己的Import类

public class MyImportSelect implements ImportSelector {@Overridepublic String[] selectImports(AnnotationMetadata annotationMetadata) {//返回值是要导入到容器中的组件全类名//annotationMetadata:注解信息return new String[]{"com.atguigu.bean.Blue", "com.atguigu.bean.Yellow"};}
}

在配置类中设置@Import导入的自定义类选择器

注意:@Import({Color.class, Red.class,MyImportSelect.class})

@Configuration
@ComponentScan(value = "com.atguigu")
@Import({Color.class, Red.class,MyImportSelect.class})
public class MainConfig {
//  @Scope("prototype")@Lazy@Bean("person")//指定bean的自定义idpublic Person person(){return new Person("张三",20);}@Conditional({WindowsCondition.class})@Bean("male")public Person personMale(){return new Person("lisi",33);}@Conditional({LinuxCondition.class})@Bean("female")public Person personFemale(){return new Person("wanger",23);}
}

测试代码

AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);@Testpublic void testImport(){printBeans(applicationContext);}private void printBeans(AnnotationConfigApplicationContext applicationContext){String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();for (String name:beanDefinitionNames) {System.out.println(name);}}

测试结果
Color,Red,Blue,Yellow都有了

org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
mainConfig
bookController
bookDAO
bookService
com.atguigu.bean.Color
com.atguigu.bean.Red
com.atguigu.bean.Blue
com.atguigu.bean.Yellow
person
female

16、使用ImportBeanDefinitionRegistrar接口导入类

自定义导入的类定义,需要实现ImportBeanDefinitionRegistrar接口,并重写 registerBeanDefinitions方法

创建一个需要被注入的类

public class RainBow {
}

创建自定义的注册类信息类

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {//annotationMetadata:当前类的注解信息//beanDefinitionRegistry:beanDefinition注册类//把所有需要添加到容器中的bean,调用beanDefinitionRegistry.registerBeanDefinition手动注册类@Overridepublic void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) {boolean red = beanDefinitionRegistry.containsBeanDefinition("com.atguigu.bean.Red");//判断定义中是否有红色boolean blue = beanDefinitionRegistry.containsBeanDefinition("com.atguigu.bean.Blue");//判断定义中是否有蓝色if(red && blue){//指定bean名RootBeanDefinition rainbowDefinition = new RootBeanDefinition(RainBow.class);//注册了一个bean,并指定了一个类名(别名)beanDefinitionRegistry.registerBeanDefinition("rainbow", rainbowDefinition);}}
}

在配置类中进行配置
注意:@Import({Color.class, Red.class,MyImportSelect.class,MyImportBeanDefinitionRegistrar.class})

@Configuration
@ComponentScan(value = "com.atguigu")
@Import({Color.class, Red.class,MyImportSelect.class,MyImportBeanDefinitionRegistrar.class})
public class MainConfig {
//  @Scope("prototype")@Lazy@Bean("person")//指定bean的自定义idpublic Person person(){return new Person("张三",20);}@Conditional({WindowsCondition.class})@Bean("male")public Person personMale(){return new Person("lisi",33);}@Conditional({LinuxCondition.class})@Bean("female")public Person personFemale(){return new Person("wanger",23);}
}

测试类

 @Testpublic void testImport(){printBeans(applicationContext);}private void printBeans(AnnotationConfigApplicationContext applicationContext){String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();for (String name:beanDefinitionNames) {System.out.println(name);}}

测试结果
显示了rainbow

org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
mainConfig
bookController
bookDAO
bookService
com.atguigu.bean.Color
com.atguigu.bean.Red
com.atguigu.bean.Blue
com.atguigu.bean.Yellow
person
female
rainbow

17、使用FactoryBean接口导入类

创建自定义工厂类,实现FactoryBean接口,并改写一下方法
getObject() //返回工厂生产的类对象
getObjectType()//返回工厂生产的类类型
isSingleton() //返回单例

创建自定义工厂类
这里实现FactoryBean接口,实现三个方法,注意泛型中使用Color类


public class ColorFactory implements FactoryBean<Color> {//返回一个Color对象,这个对象会添加到容器中@Overridepublic Color getObject() throws Exception {System.out.println("color factory generate a instance");return new Color();}@Overridepublic Class<?> getObjectType() {return Color.class;}@Overridepublic boolean isSingleton() {//true:返回单例,在容器中保存一份//false:返回多份类实例,每次获取工厂bean都会创建一个新的对象return false;}
}

在配置类中定义这个类组件
注意:
@Bean
public ColorFactory colorFactoryBean(){
return new ColorFactory();
}
}

@Configuration
@ComponentScan(value = "com.atguigu")
@Import({Color.class, Red.class,MyImportSelect.class,MyImportBeanDefinitionRegistrar.class})
public class MainConfig {
//  @Scope("prototype")@Lazy@Bean("person")//指定bean的自定义idpublic Person person(){return new Person("张三",20);}@Conditional({WindowsCondition.class})@Bean("male")public Person personMale(){return new Person("lisi",33);}@Conditional({LinuxCondition.class})@Bean("female")public Person personFemale(){return new Person("wanger",23);}@Beanpublic ColorFactory colorFactoryBean(){return new ColorFactory();}
}

测试类

public class MainTest {AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);@Testpublic void testImport(){printBeans(applicationContext);//工厂bean获取的是调用的是getObject创建的对象(Color类)Object bean1 = applicationContext.getBean("colorFactoryBean");Object bean2 = applicationContext.getBean("colorFactoryBean");System.out.println(bean1);System.out.println(bean2.getClass());//class com.atguigu.bean.ColorSystem.out.println(bean1==bean2);}private void printBeans(AnnotationConfigApplicationContext applicationContext){String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();for (String name:beanDefinitionNames) {System.out.println(name);}}

测试结果

org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
mainConfig
bookController
bookDAO
bookService
com.atguigu.bean.Color
com.atguigu.bean.Red
com.atguigu.bean.Blue
com.atguigu.bean.Yellow
person
female
colorFactoryBean
rainbow
color factory generate a instance
color factory generate a instance
com.atguigu.bean.Color@79c97cb
class com.atguigu.bean.Color
false

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

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

相关文章

Spring源码(二)Spring底层架构核心概念解析

1、BeanDefinition BeanDefinition表示Bean定义&#xff0c;BeanDefinition中存在很多属性用来描述一个Bean的特点。比如&#xff1a; class&#xff0c;表示Bean类型scope&#xff0c;表示Bean作用域&#xff0c;单例或原型等lazyInit&#xff1a;表示Bean是否是懒加载initM…

Hbase基础概念

HBase 一、HBase的数据模型1.HBase数据存储结构2.HBase存储概念3.HBase基本架构 二、HBase Shell1.DDL(Data Definition Language)1.namespace2.table 2.DML&#xff08;Data Manipulation Language&#xff09;1.写入数据2.读取数据3.删除数据 三、HBase组成架构1. Master架构…

STM32 CubeMX 定时器(普通模式和PWM模式)

STM32 CubeMX STM32 CubeMX 定时器&#xff08;普通模式和PWM模式&#xff09; STM32 CubeMXSTM32 CubeMX 普通模式一、STM32 CubeMX 设置二、代码部分STM32 CubeMX PWM模式一、STM32 CubeMX 设置二、代码部分总结 STM32 CubeMX 普通模式 一、STM32 CubeMX 设置 二、代码部分 …

使用Pytest生成HTML测试报告

背景 最近开发有关业务场景的功能时&#xff0c;涉及的API接口比较多&#xff0c;需要自己模拟多个业务场景的自动化测试&#xff08;暂时不涉及性能测试&#xff09;&#xff0c;并且在每次测试完后能够生成一份测试报告。 考虑到日常使用Python自带的UnitTest&#xff0c;所…

【JVM】详细解析java创建对象的具体流程

目录 一、java创建对象的几种方式 1.1、使用new关键字 1.2、反射创建对象 1.2.1、Class.newInstance创建对象 1.2.2、调用构造器再去创建对象Constructor.newInstance 1.3、clone实现 1.4、反序列化 二、创建对象的过程 2.1、分配空间的方式 1、指针碰撞 2、空闲列表 …

ElementUI 实现动态表单数据校验(已解决)

文章目录 &#x1f34b;前言&#xff1a;&#x1f34d;正文1、探讨需求2、查阅相关文档&#xff08;[element官网](https://element.eleme.cn/#/zh-CN/component/form)&#xff09;官方动态增减表单项示例3、需求完美解决4、注意事项 &#x1f383;专栏分享&#xff1a; &#…

小研究 - 浅析 JVM 中 GC 回收算法与垃圾收集器

本文主要介绍了JVM虚拟机中非常重要的两个部分&#xff0c;GC 回收算法和垃圾收集器。从可回收对象的标记开始&#xff0c;详细介绍 了四个主流的GC算法&#xff0c;详细总结了各自的算法思路及优缺点&#xff0c; 提出了何种情况下应该通常选用哪种算法。 目录 1 标记可回收对…

uniapp项目的pdf文件下载与打开查看

最近写的uniapp项目需要新增一个pdf下载和打开查看功能&#xff0c;摸索了半天终于写了出来&#xff0c;现分享出来供有需要的同行参考&#xff0c;欢迎指正 async function DownloadSignature() {//请求后端接口&#xff0c;返回值为一个url地址let resawait req.flow.flowDo…

【Linux基础】WSL安装Ubuntu

说明 本文使用的Windows环境是Windows 11 专业版。 WSL现在有二代WSL2&#xff0c;后续都通过WSL2来安装Linux&#xff0c;使用的是Ubuntu发行版&#xff0c;版本是20.04。 安装过程使用了PowerShell&#xff0c;且是管理员权限打开的。 参考适用于 Linux 的 Windows 子系统…

多线程面试相关的一些问题

面试题 1. 常见的锁策略相关的面试题 2. CAS相关的面试题 3. Synchronized 原理相关的面试题 4. Callable 接口相关的面试题 1. 常见的锁策略 乐观锁 vs 悲观锁 悲观锁: 总是假设最坏的情况&#xff0c;每次去拿数据的时候都认为别人会修改&#xff0c;所以每次在拿数据的时候都…

【深度学习】生成对抗网络Generative Adversarial Nets

序言 本文是GAN网络的原始论文&#xff0c;发表于2014年&#xff0c;我们知道&#xff0c;对抗网络是深度学习中&#xff0c;CNN基础上的一大进步&#xff1b; 它最大的好处是&#xff0c;让网络摆脱训练成“死模型”到固定场所处去应用&#xff0c;而是对于变化的场景&#xf…

一条sql查询语句在mysql中的执行过程是什么

mysql的连接器 我们想要在mysql中执行一条sql查询语句&#xff0c;首先需要连接到mysql服务&#xff0c;那么客户端首先要向mysql服务端发起连接请求&#xff0c;我们可以在客户端用mysql -h [ip] -P [port] -u 用户名 -p 密码 命令向服务端发起连接请求&#xff0c;这个连接请…

16位S912ZVML32F3MKH、S912ZVML31F1WKF、S912ZVML31F1MKH混合信号MCU,适用于汽车和工业电机控制应用。

S12 MagniV微控制器是易于使用且高度集成的混合信号MCU&#xff0c;非常适合用于汽车和工业应用。S12 MagniV MCU提供单芯片解决方案&#xff0c;是基于成熟的S12技术的完整系统级封装 (SiP) 解决方案&#xff0c;在整个产品组合内软件和工具都兼容。 S12 MagniV系统级封装 (S…

通过IDEA发送QQ邮箱信息

先创建一个普通的Maven项目&#xff0c;我就不演示啦&#xff0c;个人博客已经写过~[创建一个maven项目]。 项目创建成功后&#xff0c;引人Maven依赖&#xff0c;如下: <dependencies><dependency><groupId>org.apache.commons</groupId><artifact…

在k8s集群内搭建Prometheus监控平台

基本架构 Prometheus由SoundCloud发布&#xff0c;是一套由go语言开发的开源的监控&报警&时间序列数据库的组合。 Prometheus的基本原理是通过HTTP协议周期性抓取被监控组件的状态&#xff0c;任意组件只要提供对应的HTTP接口就可以接入监控。不需要任何SDK或者其他的…

大数据_Hadoop_Parquet数据格式详解

之前有面试官问到了parquet的数据格式&#xff0c;下面对这种格式做一个详细的解读。 参考链接 &#xff1a; 列存储格式Parquet浅析 - 简书 Parquet 文件结构与优势_parquet文件_KK架构的博客-CSDN博客 Parquet文件格式解析_parquet.block.size_davidfantasy的博客-CSDN博…

Redis学习路线(6)—— Redis的分布式锁

一、分布式锁的模型 &#xff08;一&#xff09;悲观锁&#xff1a; 认为线程安全问题一定会发生&#xff0c;因此在操作数据之前先获取锁&#xff0c;确保线程串行执行。例如Synchronized、Lock都属于悲观锁。 优点&#xff1a; 简单粗暴缺点&#xff1a; 性能略低 &#x…

Qt 4. 发布exe

把ex2.exe放在H盘Ex2文件夹下&#xff0c;执行 H:\Ex2>windeployqt ex2.exe H:\Ex2>windeployqt ex2.exe H:\Ex2\ex2.exe 64 bit, release executable Adding Qt5Svg for qsvgicon.dll Skipping plugin qtvirtualkeyboardplugin.dll due to disabled dependencies (Qt5…

go 查询采购单设备事项[小示例]V2-两种模式{严格,包含模式}

第一版&#xff1a; https://mp.csdn.net/mp_blog/creation/editor/131979385 第二版&#xff1a; 优化内容&#xff1a; 检索数据的两种方式&#xff1a; 1.严格模式--找寻名称是一模一样的内容&#xff0c;在上一个版本实现了 2.包含模式&#xff0c;也就是我输入检索关…

舌体分割的初步展示应用——依托Streamlit搭建demo

1 前言 去年在社区发布了有关中医舌象诊断的博文&#xff0c;其中舌象识别板块受到了极高的关注和关注。&#x1f60a;最近&#xff0c;我接触到了Python的Streamlit库&#xff0c;它可以帮助数据相关从业人员轻松搭建数据看板。本文将介绍如何使用Streamlit构建舌体分割的演示…