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

门户网站建设开发需要注意什么无锡网站推广公司

门户网站建设开发需要注意什么,无锡网站推广公司,网站开发用软件,简述网页设计的开发流程介绍 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.khdw.cn/news/69899.html

相关文章:

  • 电信做网站吗dw网站制作
  • php网站开发背景介绍深圳产品网络推广
  • 长春网站建设索q479185700腾讯广告推广平台入口
  • 烟台网站建设技术托管国内手机怎么上google浏览器
  • 邯郸手机网站开发价格bt蚂蚁
  • 免费建电子商务网站百度指数查询
  • 做政府网站建设哪家好跨境电商平台有哪些?
  • 室内设计效果图多少钱四川seo选哪家
  • 做类似于58同城的网站seo检查工具
  • 生物科技企业网站做的比较好的关键词优化公司哪家强
  • 个人如何建设电子商务网站宁波网站制作与推广价格
  • 做胎压的网站自助建站seo
  • 个人可以做哪些网站app推广接单平台哪个好
  • 网站续费合同网络营销策划包括哪些内容
  • 做微信网站要多少钱星乐seo网站关键词排名优化
  • 做网站 分工互联网营销师证书含金量
  • 网站建设公司源码 aspseo技术是什么
  • 咖啡网站建设设计规划书网站运营培训学校
  • 深圳 网站开发公司中国十大营销策划机构
  • html网站标签搜索引擎排名优化方法
  • 织梦网站广告代码如何写下载百度2023最新版安装
  • 做空机构的网站厦门seo管理
  • 郑州做网站公司电话网页制作平台有哪些
  • 视频聊天室网站开发手机建站
  • 佛山网站建设推广seo资讯网
  • html5的网站有哪些海口做网站的公司
  • 乐清市宏杉网络科技有限公司泰州seo排名扣费
  • 新品发布会宣传文案百度官方优化指南
  • 做问卷不花钱的网站东莞疫情最新消息今天中高风险区
  • 建俄语网站哪个公司最好seo软件哪个好