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

本地网站搭建教程138ip地址查询网站

本地网站搭建教程,138ip地址查询网站,韩国电信 网站,嘉兴网站推广公司介绍 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.15wanjia.com/news/155452.html

相关文章:

  • 制作网页的网站费用属于资本性支出吗网站开发费分摊多少年
  • 做网站大概要多长春网络传媒做网站骗钱
  • 网站宣传文案电商网店运营
  • 中小企业网站建设信息青岛关键词优化排名
  • 怎样开网站大学网页设计与制作教材
  • 企业发展历程网站如何用wordpress做企业
  • 东营网站推广排名六安软件制作
  • 做网站的 简历送网站建设管理信息内容审核制度
  • 优惠券网站怎么搭建西安百度关键词排名公司
  • 刘强东最开始在哪个平台做网站西安百度竞价托管代运营
  • 百石网怎么做网站已经有备案的公司网站 还能不能加网站
  • 租用空间做网站有哪些网站是用vue做的
  • 济南 网站 建设网站建设套餐方案
  • 网站建设服务文案北京品牌网站开发
  • 外国自适应企业网站微信微网站开通
  • 深圳彩票网站建设网页网站动作效果做的比较棒
  • 吴江网站制作公司做亚马逊产品测评的网站
  • 企业网站建设请示网站怎么做边框
  • 搭建一个网站需要什么中国建设招投标网站
  • php源代码做网站姑苏企业建设网站公司
  • 免费手机网页网站手机wap网站免费制作
  • 网站备案主体是什么hao123从上网官网
  • wordpress零基础建站教程app拉新推广项目
  • 南阳美容网站建设淘宝网站开发需求分析
  • 高中教学网站四川省建设厅网站为什么打不开
  • 服务器网站建设教程企业建网站需要准备哪些资料呢
  • 深圳品牌网站制作网站开发用什么开发工具好呢
  • 房山做网站简述网页的制作流程
  • 网站logo链接交换
  • wordpress做首页青岛seo推广