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

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

相关文章:

spring注解驱动开发(一)

1、需要导入的spring框架的依赖 <dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.3.12.RELEASE</version></dependency>2、Configuration 设置类为配置类 3、Annota…...

Vue3搭建启动

Vue3搭建&启动 一、创建项目二、启动项目三、配置项目1、添加编辑器配置文件2、配置别名3、处理sass/scss4、处理tsx(不用的话可以不处理) 四、添加Eslint 一、创建项目 npm create vite 1.project-name 输入项目名vue3-vite 2.select a framework 选择框架 3.select a var…...

阻塞队列(模拟实现)

概念 阻塞队列是带有阻塞功能的队列 特性 当队列满的时候&#xff0c;继续入队列&#xff0c;就会出现阻塞&#xff0c;阻塞到其他线程从队列中取走元素为止 当队列空的时候&#xff0c;继续出队列&#xff0c;也会发生阻塞&#xff0c;阻塞到其他线程往队列中添加元素为止 特…...

VScode中python的相对路径与绝对路径 FileNotFoundError: [Errno 2] No such file or directory

VScode中&#xff0c;python里的相对路径是相对于当前工作目录来定位的&#xff0c;而当前的工作目录在VScode中下方的终端窗口会有提示&#xff1a; 说明此时的工作目录并非当前python文件所在的目录&#xff0c;而是C:\Users\xxxxx(你的用户名)。因此&#xff0c;使用VScode…...

Unity XML2——C#读写XML

一、XML 文件的存放位置 &#xff08;一&#xff09;只读不写的 XML ​ 放在 Resouces 或者 StreamingAssets 文件夹下&#xff0c;详见 Unity基础3——Resources资源动态加载_weixin_53163894的博客-CSDN博客。 &#xff08;二&#xff09;动态存储的 XML ​ 放在 Applica…...

带wiringPi库的交叉编译 ---宿主机x86Ubuntu,目标机ARMv8 aarch64(香橙派)

带wiringPi库的交叉编译如何进行 先交叉编译wiringPi库&#xff0c;编译出的库适合香橙派&#xff0c;这时候交叉编译可执行程序的平台和链接库的格式也是正确的&#xff0c;然后通过-I和-L来指定链接的wiringPi库的头文件和库的位置&#xff0c;但是现在还没有学习过&#xf…...

数据仓库基础知识

什么是数据仓库&#xff1f; 数仓&#xff0c;DataWarehouse&#xff0c;是一个 面向主题的、集成的、稳定的、与时间相关的 数据集合。 而这个数据集合的建立&#xff0c;是为了支持管理者的决策过程。 也就是说&#xff0c;我们通过建设数仓&#xff0c;为业务中的流程改进、…...

M 芯片的 macos 系统安装虚拟机 centos7 网络配置

centos 安装之前把网络配置配好或者是把网线插好 第一步找到这个 第二步打开网络适配器 选择图中所指位置 设置好之后 开机启动 centos 第三步 开机以后 编写网卡文件保存 重启网卡就可以了&#xff0c;如果重启网卡不管用&#xff0c;则重启虚拟机即可 “ ifcfg-ens160 ” 这…...

AcWing 3708. 求矩阵的鞍点

输入样例&#xff1a; 3 4 1 2 3 4 1 2 3 4 1 2 3 4输出样例&#xff1a; 1 4 4 2 4 4 3 4 4 #include<bits/stdc.h> using namespace std; const int N1010; int n,m,a[N][N],x[N],y[N],flag1; int main(){scanf("%d%d",&n,&m);for(int i1;i<n;i…...

web前端开发工程师的具体职责范本(合集)

web前端开发工程师的具体职责范本1 职责&#xff1a; 1.负责web前端架构的搭建&#xff0c;核心业务功能开发和核心代码编写。 2.配合产品经理&#xff0c;实现产品UI和交互方面的需求&#xff0c;持续界面优化&#xff0c;提升用户体验。 3.参与相关业务需求变更评审。 4.…...

从源程序到可执行文件的四个过程

从源程序到可执行文件的四个过程 预处理编译汇编链接 程序要运行起来&#xff0c;必须要经过四个步骤&#xff1a;预处理、编译、汇编和链接&#xff0c;如下图所示&#xff1a; -E选项&#xff1a;提示编译器执行完预处理就停下来&#xff0c;后边的编译、汇编、链接就先不执…...

C++部署学习

gcc -E src/main.c -o src/main.i gcc -S src/main.c -o src/main.s gcc -C src/main.c -o src/main.o gcc src/main.c -o exec ./exec...

linux下lazarus开发ide里 BGRAControls控件库comboBox示例

下载开发工具 ftp://ftp.freepascal.org/pub/lazarus/releases/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.2.6/https://sourceforge.net/projects/lazarus/files/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.2.6/ sourceforge下载可能比较慢&#xff0c;选择 下载有问题&…...

Redis学习路线(9)—— Redis的场景使用

默认做好了其它的前提&#xff0c;只专注于Redis使用 一、短信登录 在没有Redis数据库时&#xff0c;我们会基于Session实现登录&#xff08;利用令牌进行授权&#xff09;&#xff0c;是怎么实现的呢&#xff1f; &#xff08;一&#xff09;基于Session的短信登录功能 1、…...

糟了,数据库主从延迟了!

前言 在实际的生产环境中&#xff0c;由单台MySQL作为独立的数据库是完全不能满足实际需求的&#xff0c;无论是在安全性&#xff0c;高可用性以及高并发等各个方面 因此&#xff0c;一般来说都是通过集群主从复制&#xff08;Master-Slave&#xff09;的方式来同步数据&…...

VUE,子组件给父组件传递参数,props 自定义属性,ref

<template><div><!-- 子传父 --><!-- 通过父组件给子组件传递函数类型的props实现&#xff1a;子给父传递数据 --><AA :getAAname"getAAname"/><h1>AA&#xff1a;{{aaname}}</h1><!-- 通过父组件给子组件绑定一个自定…...

【Oracle系列】- Oracle数据迁移

【Oracle系列】- Oracle数据迁移 文章目录 【Oracle系列】- Oracle数据迁移一、概述二、数据迁移方案三、模拟迁移方案四、迁移步骤五、迁移方案及其实施细则5.1 exp/imp逻辑备份与恢复5.2 Storage存储迁移5.3 利用data guard迁移 一、概述 最近在做公司软件系统盘点时&#x…...

Linux环境安装MySQL(详细教程)

1、下载MySQL MySQL官网&#xff1a;MySQLhttps://www.mysql.com/ 下载社区版&#xff08;免费&#xff0c;但不提供技术支持&#xff09; 简单说明一下rpm和tar包的区别&#xff1a; tar 只是一种压缩文件格式&#xff0c;所以&#xff0c;它只是把文件压缩打包 rpm&#xf…...

23. Mysql中的排序规则

文章目录 Mysql中的排序规则1. 数据库默认的排序规则2. 查看表的排序规则2.1 查看表排序规则2.2 查看字段排序规则 3.修改排序规则3.1 修改库3.2 修改表3.3 修改字段 Mysql中的排序规则 1. 数据库默认的排序规则 mysql8的默认排序方式是 utf8mb4_0900_ai_ci mysql5的默认排序…...

MongoDB 基础学习记录

MongoDB 基础 mongoDB 是由 C语言编写,基于分布式文件存储的开源数据库系统,是一个 nosql 数据库. 在高负载的情况下,添加更多的节点,保证服务器性能,MongoDB 旨在为 web 引用提供可扩展的高性能存储解决方案,将数据存储为给文档, 数据结构由键值(key,value)对组成,MongoDB 文…...

反向工程与模型迁移:打造未来商品详情API的可持续创新体系

在电商行业蓬勃发展的当下&#xff0c;商品详情API作为连接电商平台与开发者、商家及用户的关键纽带&#xff0c;其重要性日益凸显。传统商品详情API主要聚焦于商品基本信息&#xff08;如名称、价格、库存等&#xff09;的获取与展示&#xff0c;已难以满足市场对个性化、智能…...

【Oracle APEX开发小技巧12】

有如下需求&#xff1a; 有一个问题反馈页面&#xff0c;要实现在apex页面展示能直观看到反馈时间超过7天未处理的数据&#xff0c;方便管理员及时处理反馈。 我的方法&#xff1a;直接将逻辑写在SQL中&#xff0c;这样可以直接在页面展示 完整代码&#xff1a; SELECTSF.FE…...

3.3.1_1 检错编码(奇偶校验码)

从这节课开始&#xff0c;我们会探讨数据链路层的差错控制功能&#xff0c;差错控制功能的主要目标是要发现并且解决一个帧内部的位错误&#xff0c;我们需要使用特殊的编码技术去发现帧内部的位错误&#xff0c;当我们发现位错误之后&#xff0c;通常来说有两种解决方案。第一…...

Python爬虫实战:研究feedparser库相关技术

1. 引言 1.1 研究背景与意义 在当今信息爆炸的时代,互联网上存在着海量的信息资源。RSS(Really Simple Syndication)作为一种标准化的信息聚合技术,被广泛用于网站内容的发布和订阅。通过 RSS,用户可以方便地获取网站更新的内容,而无需频繁访问各个网站。 然而,互联网…...

RSS 2025|从说明书学习复杂机器人操作任务:NUS邵林团队提出全新机器人装配技能学习框架Manual2Skill

视觉语言模型&#xff08;Vision-Language Models, VLMs&#xff09;&#xff0c;为真实环境中的机器人操作任务提供了极具潜力的解决方案。 尽管 VLMs 取得了显著进展&#xff0c;机器人仍难以胜任复杂的长时程任务&#xff08;如家具装配&#xff09;&#xff0c;主要受限于人…...

【Kafka】Kafka从入门到实战:构建高吞吐量分布式消息系统

Kafka从入门到实战:构建高吞吐量分布式消息系统 一、Kafka概述 Apache Kafka是一个分布式流处理平台,最初由LinkedIn开发,后成为Apache顶级项目。它被设计用于高吞吐量、低延迟的消息处理,能够处理来自多个生产者的海量数据,并将这些数据实时传递给消费者。 Kafka核心特…...

CppCon 2015 学习:Time Programming Fundamentals

Civil Time 公历时间 特点&#xff1a; 共 6 个字段&#xff1a; Year&#xff08;年&#xff09;Month&#xff08;月&#xff09;Day&#xff08;日&#xff09;Hour&#xff08;小时&#xff09;Minute&#xff08;分钟&#xff09;Second&#xff08;秒&#xff09; 表示…...

CppCon 2015 学习:REFLECTION TECHNIQUES IN C++

关于 Reflection&#xff08;反射&#xff09; 这个概念&#xff0c;总结一下&#xff1a; Reflection&#xff08;反射&#xff09;是什么&#xff1f; 反射是对类型的自我检查能力&#xff08;Introspection&#xff09; 可以查看类的成员变量、成员函数等信息。反射允许枚…...

构建Docker镜像的Dockerfile文件详解

文章目录 前言Dockerfile 案例docker build1. 基本构建2. 指定 Dockerfile 路径3. 设置构建时变量4. 不使用缓存5. 删除中间容器6. 拉取最新基础镜像7. 静默输出完整示例 docker runDockerFile 入门syntax指定构造器FROM基础镜像RUN命令注释COPY复制ENV设置环境变量EXPOSE暴露端…...

【Linux】使用1Panel 面板让服务器定时自动执行任务

服务器就是一台24小时开机的主机&#xff0c;相比自己家中不定时开关机的主机更适合完成定时任务&#xff0c;例如下载资源、备份上传&#xff0c;或者登录某个网站执行一些操作&#xff0c;只需要编写 脚本&#xff0c;然后让服务器定时来执行这个脚本就可以。 有很多方法实现…...