Spring Boot 外部化配置(二) - @ConfigurationProperties 、@EnableConfigurationProperties
3、外部化配置的核心
接着上一章,《Spring Boot 外部化配置(一)》
3.2 @ConfigurationProperties
众所周知,当 Spring Boot 集成外部组件后,就可在 properties 或 YAML 配置文件中定义组件需要的属性,如 Redis 组件:
spring.redis.url=redis://user:password@example.com:6379
spring.redis.host=localhost
spring.redis.password=123456
spring.redis.port=6379
其中都是以 spring.redis 为前缀。这其实是 Spring Boot 为每个组件提供了对应的 Properties 配置类,并将配置文件中的属性值給映射到配置类中,而且它们有个特点,都是以 Properties 结尾,如 Redis 对应的配置类是 RedisProperties:
@ConfigurationProperties(prefix = "spring.redis")
public class RedisProperties {
private String url;
private String host = "localhost";
private String password;
private int port = 6379;
...
}
其中有个名为 @ConfigurationProperties 的注解,它的 prefix 参数就是约定好的前缀。该注解的功能就是将配置文件中的属性和 Properties 配置类中的属性进行映射,来达到自动配置的目的。这个过程分为两步,第一步是注册 Properties 配置类,第二步是绑定配置属性,过程中还涉及到一个注解,它就是 @EnableConfigurationProperties ,该注解是用来触发那两步操作的。我们以 Redis 为例来看它使用方式:
...
@EnableConfigurationProperties(RedisProperties.class)
public class RedisAutoConfiguration {
...
}
可以看到它的参数是 RedisProperties 配置类。通过前面的 《Spring Boot 自动装配(一)》 我们知道,该注解是属于 @Enable 模块注解,所以,该注解中必然有 @Import 导入的实现了 ImportSelector 或 ImportBeanDefinitionRegistrar 接口的类,具体的功能都由导入的类来实现。我们进入该注解:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(EnableConfigurationPropertiesImportSelector.class)
public @interface EnableConfigurationProperties {
/**
* Convenient way to quickly register {@link ConfigurationProperties} annotated beans
* with Spring. Standard Spring Beans will also be scanned regardless of this value.
* @return {@link ConfigurationProperties} annotated beans to register
*/
Class<?>[] value() default {};
}
果不其然,通过 @Import 导入了 EnableConfigurationPropertiesImportSelector 类,整个的处理流程都是在该类中进行处理:
class EnableConfigurationPropertiesImportSelector implements ImportSelector {
private static final String[] IMPORTS = { ConfigurationPropertiesBeanRegistrar.class.getName(),
ConfigurationPropertiesBindingPostProcessorRegistrar.class.getName() };
@Override
public String[] selectImports(AnnotationMetadata metadata) {
return IMPORTS;
}
...
}
该类实现了 ImportSelector 接口,并重写了 selectImports 方法,该方法返回的类会被 Spring 加载。可以看到这里返回了两个类,其中 ConfigurationPropertiesBeanRegistrar 就是用来注册 Properties 配置类的,而 ConfigurationPropertiesBindingPostProcessorRegistrar 则是用来绑定配置属性,且它们都实现了 ImportBeanDefinitionRegistrar 接口,会在重写的 registerBeanDefinitions 方法中进行直接注册 Bean 的操作。以上特性都在 《Spring Boot 自动装配(一)》的 3.1 小节介绍过,这里不在叙述。接下来,我们分别介绍这两个类。
3.2.1 注册 Properties 配置类
我们先来看看 ConfigurationPropertiesBeanRegistrar 是如何注册这些配置类的。我们直接进入该类的实现:
public static class ConfigurationPropertiesBeanRegistrar implements ImportBeanDefinitionRegistrar {
// 1、第一步会先执行重写的 registerBeanDefinitions 方法,
// 入参分别是 AnnotationMetadata 和 BeanDefinitionRegistry。
// AnnotationMetadata 是获取类的元数据的,如注解信息、 classLoader 等,
// BeanDefinitionRegistry 则是直接注册所需要的 Bean
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
// 2、调用 getTypes 方法,返回 Properties 配置类集合。进入 2.1 详细查看
// 3、调用 register 方法,把 Properties 配置类注册到 Spring 容器中。进入 3.1 详细查看
getTypes(metadata).forEach((type) -> register(registry, (ConfigurableListableBeanFactory) registry, type));
}
// 2.1
private List<Class<?>> getTypes(AnnotationMetadata metadata) {
// 获取指定注解的所有属性值,key是属性名称,Value是值
MultiValueMap<String, Object> attributes = metadata
.getAllAnnotationAttributes(EnableConfigurationProperties.class.getName(), false);
// 返回 key 名称为 value 的值,这里返回的就是 Properties 配置类
return collectClasses((attributes != null) ? attributes.get("value") : Collections.emptyList());
}
// 3.1
private void register(BeanDefinitionRegistry registry, ConfigurableListableBeanFactory beanFactory,
Class<?> type) {
// getName 返回的是 Bean 的名称。进入 3.2 详细查看
String name = getName(type);
// 判断有没有注册过这个 Bean
if (!containsBeanDefinition(beanFactory, name)) {
// 没有则注册该 Bean。入参是注册器、Bean 的名称、需注册的 Bean。进入 4 详细查看
registerBeanDefinition(registry, name, type);
}
}
// 3.2
private String getName(Class<?> type) {
// 获取 Properties 配置类上标注的 ConfigurationProperties 注解信息
ConfigurationProperties annotation = AnnotationUtils.findAnnotation(type, ConfigurationProperties.class);
// 获取该注解中 prefix 的属性值
String prefix = (annotation != null) ? annotation.prefix() : "";
// 最后返回的是名称格式是 属性前缀-配置类全路径名,如:
// spring.redis-org.springframework.boot.autoconfigure.data.redis.RedisProperties
return (StringUtils.hasText(prefix) ? prefix + "-" + type.getName() : type.getName());
}
// 4、
private void registerBeanDefinition(BeanDefinitionRegistry registry, String name, Class<?> type) {
assertHasAnnotation(type);
GenericBeanDefinition definition = new GenericBeanDefinition();
definition.setBeanClass(type);
// 通过 registerBeanDefinition 方法,注册 Bean 。
// 后期会有 Spring 系列的文章详细介绍该过程,到时候大家再一起讨论。
registry.registerBeanDefinition(name, definition);
}
}
执行完后,我们所有的 Properties 配置类就被注册到了 Spring 容器中。接下来,我们来看看配置文件中的数据是如何与 Properties 配置类中的属性进行绑定的。
3.2.2 绑定配置属性
我们直接进入 ConfigurationPropertiesBindingPostProcessorRegistrar 类中进行查看:
public class ConfigurationPropertiesBindingPostProcessorRegistrar implements ImportBeanDefinitionRegistrar {
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
if (!registry.containsBeanDefinition(ConfigurationPropertiesBindingPostProcessor.BEAN_NAME)) {
registerConfigurationPropertiesBindingPostProcessor(registry);
registerConfigurationBeanFactoryMetadata(registry);
}
}
...
}
这里也是在重写的 registerBeanDefinitions 方法中注册了两个 Bean,一个是 ConfigurationBeanFactoryMetadata,这个是用来存储元数据的,我们不做过多关注;另一个是 ConfigurationPropertiesBindingPostProcessor ,该类就是用来绑定属性的,我们主要对该类进行讨论:
public class ConfigurationPropertiesBindingPostProcessor
implements BeanPostProcessor, PriorityOrdered, ApplicationContextAware, InitializingBean {
...
}
可以看到,该类实现了几个接口,且都是 Spring 提供的扩展接口。这里我们简要介绍一下:
1、BeanPostProcessor:这是
Bean的后置处理器。该类有两个方法,一个是 postProcessBeforeInitialization ,Bean初始化前该方法会被调用;
另一个是 postProcessAfterInitialization ,Bean初始化后该方法会被调用;需注意的是,Spring上下文中所有Bean的初始化都会触发这两个方法。
2、ApplicationContextAware:这是Spring的Aware系列接口之一。该类有一个 setApplicationContext 方法,主要是用来获取ApplicationContext上下文对象;同理,如果是其它前缀的Aware,则获取相应前缀名的对象。
3、InitializingBean:这是Bean的生命周期相关接口。该类有一个 afterPropertiesSet 方法,当Bean的所有属性初始化后,该方法会被调用。
其中,BeanPostProcessor和InitializingBean的功能都是在Bean的生命周期中执行额外的操作。
这里我们简单的了解就行,后面会在 Spring 系列的文章中详细讨论。
接着,我们介绍该类中的方法:
public class ConfigurationPropertiesBindingPostProcessor
implements BeanPostProcessor, PriorityOrdered, ApplicationContextAware, InitializingBean {
...
public static final String VALIDATOR_BEAN_NAME = "configurationPropertiesValidator";
private ConfigurationBeanFactoryMetadata beanFactoryMetadata;
private ApplicationContext applicationContext;
private ConfigurationPropertiesBinder configurationPropertiesBinder;
// 1、这是重写的 ApplicationContextAware 接口中的方法,用来获取 ApplicationContext 上下文对象
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
// 2、这是重写的 InitializingBean 接口中的方法,当 Bean 的属性初始化后会被调用。
// 该方法主要对 ConfigurationBeanFactoryMetadata 和 ConfigurationPropertiesBinder 进行实例化
@Override
public void afterPropertiesSet() throws Exception {
this.beanFactoryMetadata = this.applicationContext.getBean(ConfigurationBeanFactoryMetadata.BEAN_NAME,
ConfigurationBeanFactoryMetadata.class);
this.configurationPropertiesBinder = new ConfigurationPropertiesBinder(this.applicationContext,
VALIDATOR_BEAN_NAME);
}
// 3、这是重写的 BeanPostProcessor 接口中的方法,在 Bean 初始化前会被调用,绑定属性的操作就是从这里开始。
// 入参 bean 就是待初始化的 Bean,beanName 就是 Bean 的名称
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
ConfigurationProperties annotation = getAnnotation(bean, beanName, ConfigurationProperties.class);
if (annotation != null) {
bind(bean, beanName, annotation);
}
return bean;
}
...
}
我们先来看第二步的 afterPropertiesSet 方法,该方法中实例化了两个类,一个是从 ApplicationContext 中获取的
ConfigurationBeanFactoryMetadata 类,是用来操作元数据的,不做过多关注;另一个是通过带参构造器初始化的 ConfigurationPropertiesBinder 类,参数是 ApplicationContext 对象和 configurationPropertiesValidator 字符串。我们进入该类的构造器中:
class ConfigurationPropertiesBinder {
private final ApplicationContext applicationContext;
private final PropertySources propertySources;
private final Validator configurationPropertiesValidator;
private final boolean jsr303Present;
...
ConfigurationPropertiesBinder(ApplicationContext applicationContext, String validatorBeanName) {
this.applicationContext = applicationContext;
this.propertySources = new PropertySourcesDeducer(applicationContext).getPropertySources();
this.configurationPropertiesValidator = getConfigurationPropertiesValidator(applicationContext,
validatorBeanName);
this.jsr303Present = ConfigurationPropertiesJsr303Validator.isJsr303Present(applicationContext);
}
...
}
该类中又实例化了四个类,我们重点关注 PropertySources 的实例化过程,具体是通过 PropertySourcesDeducer 类的 getPropertySources 方法,我们进入该类:
class PropertySourcesDeducer {
...
private final ApplicationContext applicationContext;
PropertySourcesDeducer(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
// 1、通过 extractEnvironmentPropertySources 方法,返回 MutablePropertySources 对象,
// MutablePropertySources 是 PropertySources 的实现类
public PropertySources getPropertySources() {
...
MutablePropertySources sources = extractEnvironmentPropertySources();
if (sources != null) {
return sources;
}
throw new IllegalStateException(
"Unable to obtain PropertySources from " + "PropertySourcesPlaceholderConfigurer or Environment");
}
// 2、调用 Environment 的 getPropertySources 方法,返回 MutablePropertySources
private MutablePropertySources extractEnvironmentPropertySources() {
Environment environment = this.applicationContext.getEnvironment();
if (environment instanceof ConfigurableEnvironment) {
return ((ConfigurableEnvironment) environment).getPropertySources();
}
return null;
}
...
}
看到这,大家应该比较熟悉了,Environment 就是我们在 《Spring Boot 外部化配置(一)》中 3.1 小节讲过的应用运行时的环境,通过该类可获取所有的外部化配置数据,而 MutablePropertySources 则是底层真正存储外部化配置对象的。
到这里,第二步的 afterPropertiesSet 方法就执行完了,主要是实例化了 ConfigurationPropertiesBinder 对象,而该对象中存储了所有的外部化配置。接着看第三步的 postProcessBeforeInitialization 方法:
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
ConfigurationProperties annotation = getAnnotation(bean, beanName, ConfigurationProperties.class);
if (annotation != null) {
bind(bean, beanName, annotation);
}
return bean;
}
上面说过,所有 Bean 初始化都会调用这个方法,所以先判断当前 Bean 有没有标注 @ConfigurationProperties 注解,有则表示当前 Bean 是 Properties 配置类,并调用 bind 方法对该类进行绑定属性的操作,我们进入该方法:
private void bind(Object bean, String beanName, ConfigurationProperties annotation) {
...
try {
this.configurationPropertiesBinder.bind(target);
}
catch (Exception ex) {
throw new ConfigurationPropertiesBindException(beanName, bean, annotation, ex);
}
}
这里调用了在第二步实例化的 ConfigurationPropertiesBinder 对象中的 bind 方法:
class ConfigurationPropertiesBinder {
...
public void bind(Bindable<?> target) {
...
getBinder().bind(annotation.prefix(), target, bindHandler);
}
...
private Binder getBinder() {
if (this.binder == null) {
this.binder = new Binder(getConfigurationPropertySources(), getPropertySourcesPlaceholdersResolver(),
getConversionService(), getPropertyEditorInitializer());
}
return this.binder;
}
private Iterable<ConfigurationPropertySource> getConfigurationPropertySources() {
return ConfigurationPropertySources.from(this.propertySources);
}
...
}
里面先通过 getBinder() 返回 Binder 对象。在 getBinder 方法中是通过 Binder 带参构造器创建的该对象,我们主要关注 getConfigurationPropertySources 方法返回的第一个参数:
class ConfigurationPropertiesBinder {
...
private final PropertySources propertySources;
...
private Iterable<ConfigurationPropertySource> getConfigurationPropertySources() {
return ConfigurationPropertySources.from(this.propertySources);
}
...
}
具体的是通过 ConfigurationPropertySources 中的 from 方法返回,入参 propertySources 是在第二步实例化 ConfigurationPropertiesBinder 对象时初始化好的值,里面存储的是外部化配置的源对象 PropertySource ,我们进入该方法:
public final class ConfigurationPropertySources {
...
public static Iterable<ConfigurationPropertySource> from(Iterable<PropertySource<?>> sources) {
return new SpringConfigurationPropertySources(sources);
}
...
}
最终返回的就是 SpringConfigurationPropertySources 配置源对象,在 《Spring Boot 外部化配置(一)》中讲过,该类主要是做一个适配器的工作,将 MutablePropertySources 转换为 ConfigurationPropertySource。
之后,该对象传入了 Binder 的构造器中,用于创建该对象:
public class Binder {
...
private final Iterable<ConfigurationPropertySource> sources;
...
public Binder(Iterable<ConfigurationPropertySource> sources,
PlaceholdersResolver placeholdersResolver,
ConversionService conversionService,
Consumer<PropertyEditorRegistry> propertyEditorInitializer) {
this.sources = sources;
...
}
...
}
至此, Binder 对象中就存有一份外部化配置的数据,且后续所有的绑定操作都在该类中进行。因后续中间过程实在太过庞杂,且不易理解,这里我们直接进入最后一步,对详细过程感兴趣的同学请自行研究,这里不再赘述。
进入最后阶段的 bind 方法:
// 这里着重介绍一下 BeanProperty 类,该类存储了 properties 配置类中的字段及字段的set、get方法,存储的是反射中的类。
// 如 RedisProperties 中的 url 字段,则 BeanProperty 对象中存储的是
// url 的 Field 类、setUrl 的 Method 类、getUrl 的 Method 类。
private <T> boolean bind(BeanSupplier<T> beanSupplier,
BeanPropertyBinder propertyBinder, BeanProperty property) {
// 这里获取的是字段名
String propertyName = property.getName();
// 这里获取的是字段类型
ResolvableType type = property.getType();
Supplier<Object> value = property.getValue(beanSupplier);
Annotation[] annotations = property.getAnnotations();
// 这里获取到了配置文件中的值,该值来源于 SpringConfigurationPropertySources 对象
Object bound = propertyBinder.bindProperty(propertyName,
Bindable.of(type).withSuppliedValue(value).withAnnotations(annotations));
if (bound == null) {
return false;
}
if (property.isSettable()) {
// 最后则是通过 set Method 的 invoke 方法,也就是反射的形式进行赋值。
property.setValue(beanSupplier, bound);
}
else if (value == null || !bound.equals(value.get())) {
throw new IllegalStateException(
"No setter found for property: " + property.getName());
}
return true;
}
至此,整个绑定配置属性的流程结束。可以看到,最终获取的外部化配置数据来源于前文加载的 Environment 对象。
最后来简单回顾一下 @ConfigurationProperties 注解实现配置文件中属性值和配置类属性映射的过程:
1、首先将
@ConfigurationProperties标注在Properties配置类中,参数是约定好的属性前缀。
2、然后通过@EnableConfigurationProperties来触发整个流程,参数是Properties配置类。
3、在@EnableConfigurationProperties中通过@import导入了EnableConfigurationPropertiesImportSelector类,该类中又加载了两个类,一个用来注册Properties配置类,另一个用来绑定配置属性。
4、最后,是通过反射的方式进行属性绑定,且属性值来源于Environment。
3.1.3 ConfigurationPropertiesAutoConfiguration
其实,当我们使用 @ConfigurationProperties 时,无需标注 @EnableConfigurationProperties 注解,因为 Spring Boot 在自动装配的过程中会帮我们加载一个名为 ConfigurationPropertiesAutoConfiguration 的类,该类是在 spring.factories 中定义好的:
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration
具体的自动装配过程在 《Spring Boot 自动装配(二)》 这篇文章中讨论过,这里不再赘述。我们来看看 ConfigurationPropertiesAutoConfiguration 实现:
@Configuration
@EnableConfigurationProperties
public class ConfigurationPropertiesAutoConfiguration {
}
很简单,直接通过标注 @EnableConfigurationProperties 注解来开启自动配置的流程。那这样怎么注册 Properties 配置类呢?因为上面说过,Properties 配置类是通过该注解的参数传递进来的。其实,只需在配置类上标注 @Component 注解就行了,之后会被 Spring 扫描到,然后注册。
4、总结
最后,来对 Spring Boot 外部化配置做一个整体的总结:
1、首先,外部化配置是
Spring Boot的一个特性,主要是通过外部的配置资源实现与代码的相互配合,来避免硬编码,提供应用数据或行为变化的灵活性。
2、然后介绍了几种外部化配置的资源类型,如properties和YAML配置文件类型,并介绍了获取外部化配置资源的几种方式。
3、其次,介绍了Environment类的加载流程,以及所有外部化配置加载到Environment中的底层是实现。Environment是Spring Boot外部化配置的核心类,该类存储了所有的外部化配置资源,且其它获取外部化配置资源的方式也都依赖于该类。
4、最后,介绍了Spring Boot框架中核心的@ConfigurationProperties注解,该注解是将application配置文件中的属性值和Properties配置类中的属性进行映射,来达到自动配置的目的,并带大家探讨了这一过程的底层实现。
以上就是本章的内容,如过文章中有错误或者需要补充的请及时提出,本人感激不尽。
Spring Boot 外部化配置(二) - @ConfigurationProperties 、@EnableConfigurationProperties的更多相关文章
- Spring Boot 外部化配置(一)- Environment、ConfigFileApplicationListener
目录 前言 1.起源 2.外部化配置的资源类型 3.外部化配置的核心 3.1 Environment 3.1.1.ConfigFileApplicationListener 3.1.2.关联 Spri ...
- Spring Boot外部化配置实战解析
一.流程分析 1.1 入口程序 在 SpringApplication#run(String... args) 方法中,外部化配置关键流程分为以下四步 public ConfigurableAppli ...
- Spring配置文件外部化配置及.properties的通用方法
摘要:本文深入探讨了配置化文件(即.properties)的普遍应用方式.包括了Spring.一般的.远程的三种使用方案. 关键词:.properties, Spring, Disconf, Java ...
- 曹工谈Spring Boot:Spring boot中怎么进行外部化配置,一不留神摔一跤;一路debug,原来是我太年轻了
spring boot中怎么进行外部化配置,一不留神摔一跤:一路debug,原来是我太年轻了 背景 我们公司这边,目前都是spring boot项目,没有引入spring cloud config,也 ...
- Dubbo 新编程模型之外部化配置
外部化配置(External Configuration) 在Dubbo 注解驱动例子中,无论是服务提供方,还是服务消费方,均需要转配相关配置Bean: @Bean public Applicatio ...
- 玩转Spring Boot 自定义配置、导入XML配置与外部化配置
玩转Spring Boot 自定义配置.导入XML配置与外部化配置 在这里我会全面介绍在Spring Boot里面如何自定义配置,更改Spring Boot默认的配置,以及介绍各配置的优先 ...
- SpringBoot官方文档学习(二)Externalized Configuration(外部化配置)
Spring Boot允许您将配置外部化,以便可以在不同的环境中使用相同的应用程序代码.您可以使用属性文件.YAML文件.环境变量和命令行参数来具体化配置.属性值可以通过使用@Value注释直接注入b ...
- 初识Spring Boot框架(二)之DIY一个Spring Boot的自动配置
在上篇博客初识Spring Boot框架中我们初步见识了SpringBoot的方便之处,很多小伙伴可能也会好奇这个Spring Boot是怎么实现自动配置的,那么今天我就带小伙伴我们自己来实现一个简单 ...
- Spring Boot -- 外部配置的属性使用
Spring Boot允许使用propertities文件.yaml文件或者命令行参数作为外部配置. 命令行参数配置 Spring Boot可以基于jar包运行,打成jar包的程序可以直接通过下面的命 ...
随机推荐
- tomcat-9.0.20部署后输出窗口乱码解决方案
问题:启动tomcat的时候,窗口乱码,默认都是UTF-8的,但是控制台是GBK的,要保持一致 可以通过控制台查看本机的编码: : 936 代表 GB2312 解决办法:打开tomcat目录下的c ...
- DexOpt相关的异常
查找的资料 dvm探讨之odex绕过 DexClassLoader4.4.2动态加载分析(磁盘加载分析) - ::): DexOpt: incorrect opt magic number (0xff ...
- Selenium网页自动登录项目(基于Python从0到1)
Selenium是一个自动化测试工具,利用它我们可以驱动浏览器执行特定的动作,如点击.下拉等操作. 本文讲述的是通过自动化的方式登陆某一网站,其中包含Selenium+python自动化项目环境如何部 ...
- github下载历史版本--xdd
第一步 打开一个仓库,可以看到此时在主分支下,点击1位置查看历史版本 第二步 现在可以查看到所有的版本(提交)信息,单击2位置进入该版本 第三步 单击3位置浏览并打开该版本 第四步 进入该版本之后,可 ...
- Eclipse设置Working Set管理项目和detach合并分离窗口
当项目多了的时候,使用Working Set分组管理项目很有必要了,不然一大推项目在一起 找起来麻烦,看起来也难受~ 所以根据给项目不同分类就很有必要了. 之前myeclipse设置了,今天装了一 ...
- VS Code 中文社区正式成立啦!VS Code Day 圆满落幕!
背景简介 Visual Studio Code 是一款现代化轻量级代码编辑器,它免费.开源.跨平台.功能强大.本次 VS Code Day 是广大 VS Code 爱好者一起学习与交流的盛会,让我们对 ...
- C博客作业05--2019-指针
0.展示PTA总分 1.本章学习总结 1.1 学习内容总结 1.2 本章学习体会 2.PTA实验作业 2.16 -7 输出月份英文名 2.1.1 伪代码 char* getmonth(int n) { ...
- 请求头里显示Provisional headers are shown的问题
1.问题描述: 在工作中遇到了一个坑.登录一个系统的时候,退出登录不好使了,前端确实调用了logout的接口(退出接口),但是这个接口的请求头显示Provisional headers are sho ...
- 向mysql数据表中插入数据失败的原因
1.案例代码: $sql1="insert into content(category,subject,content,username,release_date) values('{$ca ...
- LAMP架构介绍、MySQL、MariaDB介绍、MySQL安装
5月23日任务 课程内容: 11.1 LAMP架构介绍11.2 MySQL.MariaDB介绍11.3/11.4/11.5 MySQL安装扩展mysql5.5源码编译安装 http://www.ami ...