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

怎样给网站做竞价推广网站经营性备案多少钱

怎样给网站做竞价推广,网站经营性备案多少钱,wordpress主题用什么设计,安卓上搭建wordpress1. 概述 通过了解springboot加载配置#xff0c;可以更方便地封装自定义Starter。 在SpringBoot中#xff0c;可以使用以下6种方式读取 yml、properties配置#xff1a; 使用Value注解#xff1a;读取springboot全局配置文件单个配置。使用Environment接口#xff1a;通过…1. 概述 通过了解springboot加载配置可以更方便地封装自定义Starter。 在SpringBoot中可以使用以下6种方式读取 yml、properties配置 使用Value注解读取springboot全局配置文件单个配置。使用Environment接口通过Environment接口动态获取配置。将yml全部数据封装到Environment对象使用ConfigurationProperties注解在配置类上使用ConfigurationProperties注解并指定加载配置项的前缀就可以批量读取配置注入自定义类的成员变量中。自定义类需要提供setter方法使用PropertySource注解加载properties文件配置然后在字段上使用Value获取配置。配置PropertySourcesPlaceholderConfigurer的Bean加载自定义yml文件然后在字段上使用Value获取配置。Java原生方式获取配置。IO流 环境准备 1、创建maven项目不需要任何archetype模板构建 2、引入依赖 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcn.aopmin/groupIdartifactIdspringboot-loadconfig/artifactIdversion1.0.0/version!--父工程--parentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.4.5/versionrelativePath/ !-- lookup parent from repository --/parentpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependencies!-- SpringBoot配置元数据的注解处理器,可以让自定义配置实现自动补全和校验功能 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-configuration-processor/artifactIdoptionaltrue/optional/dependency!-- web起步依赖 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency!-- junit --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency!-- lombok --dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdconfigurationexcludesexcludegroupIdorg.springframework.boot/groupIdartifactIdspring-boot-configuration-processor/artifactId/exclude/excludes/configuration/plugin/plugins/build /project3、编写启动类 package cn.aopmin;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication public class LoadConfigApplication {public static void main(String[] args) {SpringApplication.run(LoadConfigApplication.class, args);} }2. 使用Value注解读取单个配置 1、编写application.yml文件配置 student:name: jackage: 202、使用Value读取配置 SpringBootTest Slf4j public class ValueTest {Value(${student.name})private String name;Value(${student.age})private Integer age;Testpublic void test() {log.info(Value 配置获取 name:{},age:{},name,age);} }Value注意事项 ①Value注解只能读取单个配置进行赋值无法读取整个配置文件批量赋值。当使用Value注解读取配置时确保配置在yml中存在否则启动程序时就会报错。注解中属性名引用方式如下 Value(${一级属性名.二级属性名...})② 当使用Value注解引用属性时可以在属性名称后面使用冒号:default-value的形式添加默认值。这样如果在配置文件中找不到对应的属性就会使用默认值。如果在配置文件中找到了属性其值将会覆盖默认值。 //可以使用各种类型的默认值包括字符串、数字、布尔值等 Value(${student.name:aopmin}) private String name;Value(${student.age:18}) private Integer age;//表示一个空字符串作为默认值 Value(${student.name:}) private String name;③ Value注解只能用于被Spring管理的Bean中使用如使用Component、Service、Controller等注解修饰的类或者使用Java配置编写的Configuration类中。 ④ Value注解可以用于字段、构造函数参数、方法参数和方法上。当将它放在方法上时Spring容器初始化时会调用该方法并将配置属性的值作为方法的参数传递进去。 Component public class MyBean {private String myProperty;Autowiredpublic MyBean(Value(${my.property}) String myProperty) {this.myProperty myProperty;}Value(${another.property})public void setAnotherProperty(String anotherProperty) {// do something with anotherProperty...}Value(${yet.another.property})public void processValue(String value) {// do something with value...}}/* Value注解被用于构造函数参数、setter方法和普通方法上。容器初始化时会将配置属性的值作为参数传递到构造函数、setter方法和普通方法中。 */⑤ Value注解不能在static修饰的字段上使用。因为Value注解是通过访问Spring容器中的上下文来解析属性值并注入到目标字段中的。由于static字段不属于对象实例无法通过实例访问容器所以在静态字段上使用Value注解是无效的。 3. 使用ConfigurationProperties注解批量绑定 1、编写application.yml文件配置 student:name: jackage: 202、使用ConfigurationProperties批量绑定 package cn.aopmin.pojo;import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;/*** 参数配置类 (需要提供setter方法)** author 白豆五* version 2023/07/16* since JDK8*/Component Data //将这个类与配置文件前缀为student的配置绑定,然后把yml、properties中关于student的配置信息注入到当前类的成员变量中 ConfigurationProperties(prefix student) public class StudentProperties {private String name; } 3、测试 SpringBootTest public class ConfigurationPropertiesTest {Autowiredprivate StudentProperties studentProperties;Testpublic void test() {System.out.println(读取配置: namestudentProperties.getName());} }ConfigurationProperties注意事项 确保添加了EnableConfigurationProperties注解为了使ConfigurationProperties生效需要在主配置类上添加EnableConfigurationProperties(valuexxxxProperties.class)注解开启ConfigurationProperties注解自动装配功能。配置文件中的属性名与类字段名的映射规则默认情况下ConfigurationProperties会将配置文件中的属性名与类字段名进行映射。例如配置文件中的属性student.name会自动映射到类字段name上。如果配置文件中的属性名与类字段名不一致可以使用Value注解或通过setter方法来指定映射关系。类必须是Spring管理的Bean被ConfigurationProperties注解标记的类必须是由Spring容器管理的Bean因此需要确保该类被Component或其他相关注解标记以便Spring能够扫描并创建该类的实例。支持类型转换ConfigurationProperties支持自动类型转换将配置文件中的字符串值转换为目标字段的类型。例如将字符串转换为整数、布尔值等。如果无法进行类型转换会抛出异常。默认值和可选属性可以为ConfigurationProperties注解的字段设置默认值以防止配置文件中缺少对应的属性。可以使用:“符号指定默认值例如Value(”${my.property:default-value})。另外可以使用required属性来指定某个属性是否为必需的。配置项的验证和校验可以使用JSR-303/349规范的注解对ConfigurationProperties注解的字段进行验证和校验。例如使用NotBlank、Min、Max等注解来限制属性值的有效性。 4. 使用Environment动态获取配置 1、编写application.yml文件配置 student:name: jackage: 202、使用Environment动态获取配置将Environment对象自动装配然后调用getProperty()方法获取指定属性值 package cn.aopmin.test;import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.core.env.Environment;import javax.annotation.Resource;/*** Environment是springboot核心的环境配置接口它提供了一些方法用于访问应用程序配置属性。* 包括系统属性、操作系统环境变量、命令行参数、以及配置文件中定义的属性等等** author 白豆五* version 2023/07/16* since JDK8*/ Slf4j SpringBootTest public class EnvironmentTest {Resourceprivate Environment env;Testpublic void test() {String name env.getProperty(student.name);// 逻辑处理...(也可以控制某一个bean是否生效)log.info(Environment配置读取: name:{}, name);}}除了自动装配方式也可以从spring容器中获取bean Slf4j SpringBootTest public class EnvironmentTest2 implements EnvironmentAware {private Environment env;Testpublic void test() {String name env.getProperty(student.name);log.info(Environment配置读取: name:{}, name);}Overridepublic void setEnvironment(Environment environment) {// 逻辑处理...(也可以控制某一个bean是否生效)this.env environment;} }Aware是Spring框架提供的一组特殊接口可以让Bean从Spring容器中拿到一些资源信息。 Aware接口是一种回调机制当Bean被实例化并注册到Spring容器中时容器会自动调用Bean中实现了特定Aware接口的方法将相应的资源或信息传递给Bean。 以下是几个常用的Aware接口 ApplicationContextAware通过实现该接口Bean可以访问ApplicationContext对象从而获取Spring容器的相关信息。 BeanFactoryAware通过实现该接口Bean可以访问BeanFactory对象从而获取Bean在容器中的相关信息。 EnvironmentAware通过实现该接口Bean可以访问Environment对象从而获取环境相关的配置属性比如系统属性、环境变量等。 ResourceLoaderAware通过实现该接口Bean可以访问ResourceLoader对象从而获取资源加载器用于加载类路径下的资源文件。 MessageSourceAware通过实现该接口Bean可以访问MessageSource对象从而获取国际化消息。 5.使用PropertySources注解获取外部配置 前3种都是从springboot全局配置文件中获取配置如果获取外部自定义文件就不可以啦我们可以通过PropertySources注解获取.properties文件配置。 1、在resources目录下创建student.properties文件 student.id1001 student.name白豆五2、在配置类中使用PropertySources注解绑定配置: package cn.aopmin.pojo;import lombok.Data; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource;/*** 绑定自定义properties配置** author 白豆五* version 2023/07/16* since JDK8*/ Data Configuration PropertySource(value classpath:student.properties, encoding UTF-8) public class PropertySourcesConf {Value(${student.id})private Integer id;Value(${student.name})private String name; } 3、测试 SpringBootTest Slf4j public class PropertySourcesTest {Resourceprivate PropertySourcesConf propertySourcesConf;Testpublic void test() {log.info(PropertySources配置读取 id: {}, propertySourcesConf.getId());log.info(name: {}, propertySourcesConf.getName());} }6. 配置PropertySourcesPlaceholderConfigurer的Bean获取外部配置 1、编写student.yml配置 file:type: 自定义yaml文件配置2、 配置PropertySourcesPlaceholderConfigurer获取自定义yml文件配置 package cn.aopmin.config;import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.io.ClassPathResource;import java.util.Objects;/*** 配置PropertySourcesPlaceholderConfigurer读取yml配置* author 白豆五* version 2023/07/16* since JDK8*/ Configuration public class MyYamlConfig {Beanpublic static PropertySourcesPlaceholderConfigurer yamlConfigurer() {PropertySourcesPlaceholderConfigurer configurer new PropertySourcesPlaceholderConfigurer();YamlPropertiesFactoryBean yaml new YamlPropertiesFactoryBean();yaml.setResources(new ClassPathResource(student.yml));//自定义yml文件//Objects.requireNonNull()方法的作用是如果对象为空则抛出空指针异常否则返回对象本身。configurer.setProperties(Objects.requireNonNull(yaml.getObject()));return configurer;} }3、测试 SpringBootTest public class LoadYamlTest {Value(${file.type})private String fileType;Testpublic void test() {System.out.println(读取yaml配置:fileType);} }7. Java原生方式获取配置 通过IO流读取配置然后放入propertis配置对象中。 package cn.aopmin.test;import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest;import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.Properties;/*** author 白豆五* version 2023/07/16* since JDK8*/ SpringBootTest public class CustomTest {Testpublic void test() {// 配置对象Properties props new Properties();InputStreamReader input null;try {// 输入流 字节流转字符流input new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(student.properties),//通过类加载器来获取指定路径下的资源文件并返回一个InputStream对象StandardCharsets.UTF_8); //指定编码格式// 加载配置props.load(input);} catch (IOException e) {throw new RuntimeException(e);} finally {if (input!null)try {input.close();} catch (IOException e) {e.printStackTrace();}}// 获取配置System.out.println(id: props.getProperty(student.id) , name: props.getProperty(student.name));} }
http://www.pierceye.com/news/858987/

相关文章:

  • 电商网站可以用dw做嘉兴网站建设平台
  • 做网站是数据库应该放在哪里建筑工程水平防护网
  • vps网站无法通过ip访问网站怎么做的支付宝接口
  • 怎么创建一个博客网站网站的c4d动画是怎么做的
  • 西安做企业网站科技论文发表网
  • html 手机网站开发企业做网站的合同
  • 建立wordpress网站吗全州建设完小网站
  • 网站域名注册证书是什么制作WordPress友情链接
  • 如何在解决方案中新建网站html网页制作的软件下载
  • 企业网站怎么做优化开小加工厂去哪接单子
  • 网站建设推广费怎么做账域名和网站绑定
  • 商丘网站建设想象力网络中国流量最大的网站排行
  • 网站是否有备案网站集约化建设建议
  • 浏览器收录网站网上做图赚钱的网站
  • 网站建设优化过程中的优化策略相关文章 wordpress
  • 泉州网站深圳航空公司官网首页
  • 百度推广整体优化网站整体软装设计公司
  • 太原搜索引擎优化招聘信息服务好的镇江网站优化
  • 自己做网站下载怎么网站基础知识域名5个点
  • 网站搭建合作协议wordpress注册页面插件
  • 网络公司最好的是哪个兰州网络推广优化怎样
  • 网站文章采集工具新网站怎么做流畅
  • discuz 手机网站模板山东省住房建设厅网站首页
  • 网站建设违约责任条款枣庄专业做网站
  • python做爬虫和做网站做两个一摸一样的网站
  • 网站做微信登录asp.net做网站头部和尾部_都用什么来实现
  • 南充哪里做网站太原关键词优化公司
  • 哪个网站做的ppt模板好投放广告网站
  • 公司网站中新闻中心怎样做优化百度浏览器电脑版
  • 厦门网站建设 九来外国做视频在线观看网站