欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot超詳細講解yaml配置文件

 更新時間:2022年06月22日 09:59:10   作者:昱晟168  
這篇文章主要介紹了SpringBoot中的yaml配置文件問題,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

1.文件類型

A.properties配置文件類型

同以前properties用法一樣

B.yaml

簡介:

YAML 是 "YAML Ain't Markup Language"(YAML 不是一種標記語言)的遞歸縮寫。在開發(fā)的這種語言時,YAML 的意思其實是:"Yet Another Markup Language"(仍是一種標記語言)。

非常適合用來做以數據為中心的配置文件

基本語法

  • key :value ;鍵值對象之間必須有一個空格
  • 大小寫敏感
  • 使用縮進表示層級關系
  • 縮進不允許使用tabl,只允許空格
  • 縮進的空格數不重要,只要相同層級元素左對齊即可
  • #表示注釋
  • 字符串無需要加引號,如果要加''或""字符串內容會被轉義或不轉義

注意是:字符串不需要加引號,如果加了''單引號或""雙引號內容會被轉義【單引號轉義】或不轉義【雙引號不轉義】

數據類型

A.字面量:

單個的,不可再分的值。date boolean string number null

K: V  #鍵值對之間必須有一個空格

B.對象 鍵值對的集合

map Object hash

#行內寫法:
K: {k1:v1,k2:v2,k3:v3}
#或者
K:
    K1: v1  #鍵值對之間必須有一個空格
    k2: v2
    k3: v3

C.數組:一組按次排列的值。

array list set queue

#行內寫法
K: [v1,v2,v3]

#或者
K:
    - v1  # `-`與`value`值一定要有一個空格
    - v2
    - v3

示例:

POJO

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Component
public class Pet {
    private String name;
    private Double weight;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Component
@ConfigurationProperties(prefix = "person")
public class Person {
    private String username;
    private Boolean boss;
    private Date birth;
    private Integer age;
    private Pet pet;
    private String[] interests;//興趣
    private List<String> animal;
    private Map<String,Object> score;
    private Set<Double> salary;
    private Map<String,List<Pet>> allPets;
}

yaml配置文件

person:
  #字面量
  username: ???br />  boss: true
  birth: 2000/11/04
  age: 21
  #對象 鍵值對
  pet:
    name: 阿狗
    weight: 20.28
  #數組
#  interests: [聽歌,打代碼,跑步] #行內寫法
  interests:
    - 聽歌
    - 打代碼
    - 跑步
  #List 集合【和數組寫法一樣】
#  animal: [阿貍,阿貓,阿狗] #行內寫法
  animal:
    - 阿貍
    - 阿狗
    - 阿貓
  #set集合【和數組寫法一樣】
#  salary: [8888.8,9999.9,28168.88] #行內寫法
  salary:
    - 88988.99
    - 978988.9
    - 9999168.98
  #Map<String,Object>集合
  score:
    java: 88.8
    C++: 88.99

  #Map<String,List<Pet>> 集合
  allPets:
    haikang:
      - name: 阿貍
        weight: 20.9
      - name: 阿狗
        weight: 30.2
    iaia: [{name: 阿聯,weight: 20},{name: 阿哈,weight: 21}]

controller控制器

@RestController// 表示該類是一個控制器并且只響應瀏覽器不進行頁面跳轉
public class HelloController {
    @Autowired
    Person person;
    @RequestMapping("/person")
    public Person person(){
        System.out.println(person);
        return  person;
    }
}

2.配置提示

由于在核心配置文件中,配置我們自定義配置信息【自定義的類和配置文件綁定】,IDEA沒有提示

例如:上述示例一樣沒有提示

配置提示步驟:

步驟1:引入依賴

在pom.xml加入

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

步驟2:加入下面插件,排除在打包時,將configuration-processor的引入打包jar

在pom.xml加入

 <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-configuration-processor</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

步驟3:重新運行RUN

例如:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-configuration-processor</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

到此這篇關于SpringBoot超詳細講解yaml配置文件的文章就介紹到這了,更多相關SpringBoot 配置文件內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Java?8函數式接口之BinaryOperator使用示例詳解

    Java?8函數式接口之BinaryOperator使用示例詳解

    這篇文章主要大家介紹了Java?8函數式接口之BinaryOperator,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-07-07
  • String s = new String(''a '') 到底產生幾個對象

    String s = new String(''a '') 到底產生幾個對象

    這篇文章主要介紹了String s = new String(" a ") 到底產生幾個對象,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-05-05
  • Java接入通義千問的簡單方法示例

    Java接入通義千問的簡單方法示例

    ? 通義千問是阿里云開發(fā)的大語言模型(Large language Model )LLM,旨在提供廣泛的知識和普適性,可以理解和回答各領域中的問題,這篇文章主要給大家介紹了關于Java接入通義千問的簡單方法,需要的朋友可以參考下
    2024-02-02
  • mybatis/mybatis-plus模糊查詢語句特殊字符轉義攔截器的實現

    mybatis/mybatis-plus模糊查詢語句特殊字符轉義攔截器的實現

    在開發(fā)中,我們通常會遇到這樣的情況。用戶在錄入信息是錄入了‘%’,而在查詢時無法精確匹配‘%’。究其原因,‘%’是MySQL的關鍵字,如果我們想要精確匹配‘%’,那么需要對其進行轉義,本文就詳細的介紹一下
    2021-11-11
  • 解決Spring?AOP攔截抽象類(父類)中方法失效問題

    解決Spring?AOP攔截抽象類(父類)中方法失效問題

    這篇文章主要介紹了解決Spring?AOP攔截抽象類(父類)中方法失效問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • 詳細了解JAVA NIO之Buffer(緩沖區(qū))

    詳細了解JAVA NIO之Buffer(緩沖區(qū))

    這篇文章主要介紹了JAVA NIO之Buffer(緩沖區(qū))的相關資料,文中講解非常細致,幫助大家更好的學習JAVA NIO,感興趣的朋友可以了解下
    2020-07-07
  • Java使用wait/notify實現線程間通信下篇

    Java使用wait/notify實現線程間通信下篇

    wait()和notify()是直接隸屬于Object類,也就是說所有對象都擁有這一對方法,下面這篇文章主要給大家介紹了關于使用wait/notify實現線程間通信的相關資料,需要的朋友可以參考下
    2022-12-12
  • MyBatis自動生成Where語句

    MyBatis自動生成Where語句

    這篇文章主要介紹了MyBatis自動生成Where語句的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-08-08
  • springsecurity第三方授權認證的項目實踐

    springsecurity第三方授權認證的項目實踐

    Spring security 是一個強大的和高度可定制的身份驗證和訪問控制框架,本文主要介紹了springsecurity第三方授權認證的項目實踐,具有一定的參考價值,感興趣可以了解一下
    2023-08-08
  • Intellij IDEA遠程debug教程實戰(zhàn)和要點總結(推薦)

    Intellij IDEA遠程debug教程實戰(zhàn)和要點總結(推薦)

    這篇文章主要介紹了Intellij IDEA遠程debug教程實戰(zhàn)和要點總結(推薦),本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-03-03

最新評論