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

门户网站建设开发需要注意什么网址外链平台

门户网站建设开发需要注意什么,网址外链平台,同ip下网站,win7本地架设网站介绍 Spring Boot中的Binder类是一个用于绑定属性的工具类。它可以将配置文件中的属性值绑定到Java对象中,从而方便地进行配置管理。 简单示例 import org.springframework.boot.context.properties.bind.Binder; import org.springframework.core.env.Environmen…

介绍

Spring Boot中的Binder类是一个用于绑定属性的工具类。它可以将配置文件中的属性值绑定到Java对象中,从而方便地进行配置管理。


简单示例

import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.core.env.Environment;@Data
public class MyConfig {private String name;private int age;public MyConfig(Environment environment) {Binder binder = Binder.get(environment);this.name = binder.bind("myconfig.name", String.class).orElse("lucifer");this.age = binder.bind("myconfig.age", Integer.class).orElse(25);}
}

使用Binder类将配置文件中的属性值绑定到这些属性中。在构造函数中,首先获取了一个Binder实例,然后使用bind方法将配置文件中的属性值绑定到Java对象中。如果属性不存在,则使用默认值。


配置文件中属性:

myconfig.name=John
myconfig.age=25

需要将Environment对象传递给MyConfig的构造函数,以便Binder类可以访问配置文件中的属性值。在Spring Boot应用程序中,可以通过@Autowired注解将Environment对象注入到MyConfig类中。

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;@Configuration
public class AppConfig {@Autowiredprivate Environment environment;public MyConfig myConfig() {return new MyConfig(environment);}
}

常用方法

  • bind方法:将配置文件中的属性值绑定到Java对象中。
@ConfigurationProperties(prefix = "example")
@Data
public class ExampleProperties {private String name;private int age;
}ExampleProperties properties = new ExampleProperties();
Binder binder = Binder.get(environment);
binder.bind("example", Bindable.ofInstance(properties));
  • bindOrCreate方法:如果Java对象不存在,则创建一个新的对象并将配置文件中的属性值绑定到该对象中。
ExampleProperties properties = Binder.get(environment).bindOrCreate("example", Bindable.of(ExampleProperties.class));
  • bindProperty方法:将配置文件中的单个属性值绑定到Java对象的属性中。
ExampleProperties properties = new ExampleProperties();
Binder binder = Binder.get(environment);
binder.bindProperty("example.name", Bindable.ofInstance(properties), String.class);
  • bindAnnotations方法:将Java对象中带有@ConfigurationProperties注解的属性绑定到配置文件中的属性值。
@Data
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {private String name;private int age;
}ExampleProperties properties = new ExampleProperties();
Binder binder = Binder.get(environment);
binder.bindAnnotations(properties);
http://www.dinnco.com/news/22396.html

相关文章:

  • o2o网站建设方案浙江seo外包费用
  • 乌鲁木齐高新区建设局网站郑州网站优化公司
  • 历下区城乡建设委员会门户网站如何实现网站的快速排名
  • 网站更新前知道内容青岛官网优化
  • 上海企业网站制作哪家好百度网址大全 官网首页
  • 帮别人做网站需要什么能力seo优化外包
  • 福州网站建站建设天津seo结算
  • 网站备案幕布要求网络推广怎么做?
  • 沈阳市住房和城乡建设局网站首页互联网站
  • 学校门户网站怎么做百度浏览器网址链接
  • 网页与网站设计说明自助网站建设平台
  • 股票实时交易网站开发软文推广公司
  • 十万pv的网站建设成人就业技术培训机构
  • 汉中网站建设服务深圳网站优化推广
  • 用asp做网站需要什么软件北京网聘咨询有限公司
  • 公司网络推广怎么做电商seo是什么意思
  • 阿里云服务器年费多少郑州seo培训
  • 怎么做外围网站的代理外贸网络推广
  • 网站开发技术主管工作职责设计网站排行榜前十名
  • 青岛建设系统一体化网站推广软文300字
  • 网站宣传怎么做淘宝关键词搜索排行榜
  • 品牌营销包括哪些内容温州seo按天扣费
  • 网站开发的内容和特点全球十大搜索引擎排名
  • 2015做微网站多少钱上海培训机构整顿
  • 菏砖网站建设品牌整合营销
  • 网上学做网站关键词竞价排名
  • 百科网站开发yahoo搜索引擎
  • 网站内容上传要求软文是什么文章
  • 素材网站个人做的seo点击排名软件哪家好
  • 做网站招微商卖货是真的吗西安seo教程