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种方法
- 包扫描+组件类上标注注解:(@Controller,@Service,@Repository,@Component)
- @Bean:导入第三方包的组件
- @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…...
阻塞队列(模拟实现)
概念 阻塞队列是带有阻塞功能的队列 特性 当队列满的时候,继续入队列,就会出现阻塞,阻塞到其他线程从队列中取走元素为止 当队列空的时候,继续出队列,也会发生阻塞,阻塞到其他线程往队列中添加元素为止 特…...

VScode中python的相对路径与绝对路径 FileNotFoundError: [Errno 2] No such file or directory
VScode中,python里的相对路径是相对于当前工作目录来定位的,而当前的工作目录在VScode中下方的终端窗口会有提示: 说明此时的工作目录并非当前python文件所在的目录,而是C:\Users\xxxxx(你的用户名)。因此,使用VScode…...
Unity XML2——C#读写XML
一、XML 文件的存放位置 (一)只读不写的 XML 放在 Resouces 或者 StreamingAssets 文件夹下,详见 Unity基础3——Resources资源动态加载_weixin_53163894的博客-CSDN博客。 (二)动态存储的 XML 放在 Applica…...

带wiringPi库的交叉编译 ---宿主机x86Ubuntu,目标机ARMv8 aarch64(香橙派)
带wiringPi库的交叉编译如何进行 先交叉编译wiringPi库,编译出的库适合香橙派,这时候交叉编译可执行程序的平台和链接库的格式也是正确的,然后通过-I和-L来指定链接的wiringPi库的头文件和库的位置,但是现在还没有学习过…...
数据仓库基础知识
什么是数据仓库? 数仓,DataWarehouse,是一个 面向主题的、集成的、稳定的、与时间相关的 数据集合。 而这个数据集合的建立,是为了支持管理者的决策过程。 也就是说,我们通过建设数仓,为业务中的流程改进、…...

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

AcWing 3708. 求矩阵的鞍点
输入样例: 3 4 1 2 3 4 1 2 3 4 1 2 3 4输出样例: 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 职责: 1.负责web前端架构的搭建,核心业务功能开发和核心代码编写。 2.配合产品经理,实现产品UI和交互方面的需求,持续界面优化,提升用户体验。 3.参与相关业务需求变更评审。 4.…...

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

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下载可能比较慢,选择 下载有问题&…...
Redis学习路线(9)—— Redis的场景使用
默认做好了其它的前提,只专注于Redis使用 一、短信登录 在没有Redis数据库时,我们会基于Session实现登录(利用令牌进行授权),是怎么实现的呢? (一)基于Session的短信登录功能 1、…...

糟了,数据库主从延迟了!
前言 在实际的生产环境中,由单台MySQL作为独立的数据库是完全不能满足实际需求的,无论是在安全性,高可用性以及高并发等各个方面 因此,一般来说都是通过集群主从复制(Master-Slave)的方式来同步数据&…...
VUE,子组件给父组件传递参数,props 自定义属性,ref
<template><div><!-- 子传父 --><!-- 通过父组件给子组件传递函数类型的props实现:子给父传递数据 --><AA :getAAname"getAAname"/><h1>AA:{{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官网:MySQLhttps://www.mysql.com/ 下载社区版(免费,但不提供技术支持) 简单说明一下rpm和tar包的区别: tar 只是一种压缩文件格式,所以,它只是把文件压缩打包 rpm…...
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 文…...
浏览器访问 AWS ECS 上部署的 Docker 容器(监听 80 端口)
✅ 一、ECS 服务配置 Dockerfile 确保监听 80 端口 EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]或 EXPOSE 80 CMD ["python3", "-m", "http.server", "80"]任务定义(Task Definition&…...

利用最小二乘法找圆心和半径
#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …...

eNSP-Cloud(实现本地电脑与eNSP内设备之间通信)
说明: 想象一下,你正在用eNSP搭建一个虚拟的网络世界,里面有虚拟的路由器、交换机、电脑(PC)等等。这些设备都在你的电脑里面“运行”,它们之间可以互相通信,就像一个封闭的小王国。 但是&#…...

19c补丁后oracle属主变化,导致不能识别磁盘组
补丁后服务器重启,数据库再次无法启动 ORA01017: invalid username/password; logon denied Oracle 19c 在打上 19.23 或以上补丁版本后,存在与用户组权限相关的问题。具体表现为,Oracle 实例的运行用户(oracle)和集…...

装饰模式(Decorator Pattern)重构java邮件发奖系统实战
前言 现在我们有个如下的需求,设计一个邮件发奖的小系统, 需求 1.数据验证 → 2. 敏感信息加密 → 3. 日志记录 → 4. 实际发送邮件 装饰器模式(Decorator Pattern)允许向一个现有的对象添加新的功能,同时又不改变其…...
进程地址空间(比特课总结)
一、进程地址空间 1. 环境变量 1 )⽤户级环境变量与系统级环境变量 全局属性:环境变量具有全局属性,会被⼦进程继承。例如当bash启动⼦进程时,环 境变量会⾃动传递给⼦进程。 本地变量限制:本地变量只在当前进程(ba…...
PHP和Node.js哪个更爽?
先说结论,rust完胜。 php:laravel,swoole,webman,最开始在苏宁的时候写了几年php,当时觉得php真的是世界上最好的语言,因为当初活在舒适圈里,不愿意跳出来,就好比当初活在…...

Day131 | 灵神 | 回溯算法 | 子集型 子集
Day131 | 灵神 | 回溯算法 | 子集型 子集 78.子集 78. 子集 - 力扣(LeetCode) 思路: 笔者写过很多次这道题了,不想写题解了,大家看灵神讲解吧 回溯算法套路①子集型回溯【基础算法精讲 14】_哔哩哔哩_bilibili 完…...
GitHub 趋势日报 (2025年06月08日)
📊 由 TrendForge 系统生成 | 🌐 https://trendforge.devlive.org/ 🌐 本日报中的项目描述已自动翻译为中文 📈 今日获星趋势图 今日获星趋势图 884 cognee 566 dify 414 HumanSystemOptimization 414 omni-tools 321 note-gen …...
C# SqlSugar:依赖注入与仓储模式实践
C# SqlSugar:依赖注入与仓储模式实践 在 C# 的应用开发中,数据库操作是必不可少的环节。为了让数据访问层更加简洁、高效且易于维护,许多开发者会选择成熟的 ORM(对象关系映射)框架,SqlSugar 就是其中备受…...