当前位置: 首页 > 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.mmbaike.com/news/56855.html

相关文章:

  • 网站你应该知道我说的是什么吧百度怎么进入官方网站
  • 做类似电影天堂的网站违法吗网站提交百度收录
  • 如何做vip微信电影网站百度软件市场
  • 网站分析怎么写亚马逊seo关键词优化软件
  • 做网站的得多少钱经典广告语
  • 品牌设计网站大全网络推广优化seo
  • 高端网站建设的公司营销策划的十个步骤
  • 苏州做网站推广最新最好的磁力搜索
  • 网站seo诊断报告今天的新闻有哪些
  • 温州网站推广效果好永久免费的建站系统有哪些
  • 绍兴专门做网站的公司2023百度秒收录技术
  • 中小学生在线做试卷的网站6北京seo推广
  • ipv6在家做网站万网查询
  • 菏泽做网站公司个人购买链接
  • 域名注册需要什么资料网站优化要做哪些
  • 时时彩网站做号丈哥seo博客工具
  • 品牌建设 政府做什么搜索引擎优化岗位
  • 网站管理员怎么做板块建设路由优化大师
  • 模板网站的建设方式与方法今日头条国际新闻
  • 做地方服务性网站产品推广方案模板
  • 做网站优化两年遇到的SEO常态网站推广专家
  • 重庆网站设计定制2019年度最火关键词
  • 丽水市做网站的优化关键词怎么做
  • 济南做网站的机构有哪些太原百度快速优化
  • 昌黎县城乡建设局网站厦门seo优化公司
  • 自己的网站如何优化郑州seo外包v1
  • 免费网站制作作业口碑营销的案例
  • 电商网站建设技术交流问题兔子bt樱桃搜索磁力天堂
  • 曲靖做网站建设的公司廊坊seo排名霸屏
  • 恐怖小说网站怎么做百度seo官方网站