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

市场调研公司和咨询公司seo是什么意思新手怎么做seo

市场调研公司和咨询公司,seo是什么意思新手怎么做seo,dw网页制作实例素材打包下载,水网站源码在 Spring Boot 项目中,我们经常使用 YAML 文件来配置应用程序的属性。在这篇博客中,我将模拟如何在 Java 的 Spring Boot 项目中读取 YAML 文件中的数组、集合和 HashMap。 1. 介绍 YAML(YAML Aint Markup Language)是一种人类…

在 Spring Boot 项目中,我们经常使用 YAML 文件来配置应用程序的属性。在这篇博客中,我将模拟如何在 Java 的 Spring Boot 项目中读取 YAML 文件中的数组、集合和 HashMap。

1. 介绍

YAML(YAML Ain't Markup Language)是一种人类可读的数据序列化格式,通常用于配置文件。在 Spring Boot 中,我们可以使用 @ConfigurationProperties 注解和 application.yml 文件轻松管理应用程序的配置。

2. 准备工作

首先,确保你的 Spring Boot 项目中包含以下依赖:

        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency>

3. 创建 YAML 文件

src/main/resources 目录下创建一个名为 application.yml 的文件,并添加以下内容:

server:port: 6666
lps:languages:- Java- Python- C- C++- C#colors:- red- green- bluefruits:- name : appleprice : 3.88- name : bananaprice : 2.88- name : orangeprice : 5.28ages:john: 30alice: 25bob: 35

这个文件包含了两个数组、一个水果列表和一个年龄的 HashMap。

4. 创建配置类

创建一个 Java 配置类,用于将 YAML 文件中的属性映射到对象。创建一个名为 AppProperties.java 的文件:

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;/*** @author 阿水* @ClassName LpsProperties * @description: TODO* @date 2023年11月26日* @version: 1.0*/
@Component
@ConfigurationProperties(prefix = "lps")
@Data
public class LpsProperties {private String[] languages;private List<String> colors;private List<Fruits> fruits;private Map<String, Integer> ages;@Datapublic static class Fruits {private String name;private Double price;}
}

5. 注入配置类

在你的服务或组件中,通过 @Autowired 注解将 AppProperties 配置类注入,然后访问其中的属性:

 @AutowiredLpsProperties lpsProperties;

6. 运行项目

在你的应用程序中使用 LpsProperties类,并调用方法,你将能够从 YAML 文件中读取数组、集合和 HashMap,并在控制台上输出它们。

@SpringBootTest
class CountDemoApplicationTests {@AutowiredLpsProperties lpsProperties;@Testvoid contextLoads() {String[] languages = lpsProperties.getLanguages();System.out.print("常见编程语言:");for (String language : languages) {System.out.print(language + " ");}System.out.println("等等");System.out.println("----------------------");Map<String, Integer> ages = lpsProperties.getAges();ages.forEach((key, value) -> System.out.println(key + "今年" + value + "岁"));System.out.println("----------------------");List<String> colors = lpsProperties.getColors();for (String color : colors) {System.out.println("收到的颜色为:" + color);}System.out.println("----------------------");List<LpsProperties.Fruits> fruits = lpsProperties.getFruits();fruits.forEach(fruit -> System.out.println(fruit));}}

7. 结论

通过使用 @ConfigurationProperties 注解和 YAML 文件,我们可以轻松地将配置属性映射到 Java 对象中。这使得在 Spring Boot 项目中管理数组、集合和 HashMap 的配置变得简单而直观。

希望这篇博客对你在 Spring Boot 项目中读取 YAML 文件中的数组、集合和 HashMap 有所帮助。如有疑问或建议,请随时提出。

http://www.yidumall.com/news/60590.html

相关文章:

  • wordpress引用b站视频百度网页游戏大厅
  • 柳州网站推广最好的公司长沙服务好的网络营销
  • 有移动端网站 怎么做app搭建网站基本步骤
  • 惠州做网站哪家公司好怎么在百度上发布广告
  • 青海网站制作软文网站模板
  • 哪个公司建网站最好代写文章多少钱
  • 建立网站视频教程天津企业seo
  • 免费软件安装网站seo报价单
  • 新锐媒体网站建设方案网站关键词优化软件
  • 西昌市做网站的青岛seo排名公司
  • 南汇网站建设中山百度推广公司
  • 百度站长工具网站认证搜索网站
  • 做网站买阿里云的ecs服务器网络营销的12种手段
  • 做最精彩绳艺网站网页制作接单
  • 无为做网站深圳市社会组织总会
  • 当前政府网站建设存在的问题及对策海外网站建站
  • 晋中网站建设哪家强成都百度提升优化
  • 医美行业网站建设seo需求
  • 学校网站建设报价是多少品牌策划方案案例
  • 孝感的网站建设steam交易链接怎么看
  • 开发板有哪些广东seo推广
  • 做黑网站赚钱郑州网站定制
  • 可以免费创建网站的软件千锋教育培训怎么样
  • 网站建设的宿主选择最新疫情爆发
  • 网站开发建设的步骤培训心得总结
  • 企业站群cms郴州网站seo外包
  • 电子商务网站开发工具赣州网站建设
  • 广东深圳公司网站优化是什么
  • 网站开发php岗位职责视频营销成功的案例
  • 优速网站建设seo技术培训中心