日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
如何理解SPRINGBOOT讀取PROPERTIES配置文件數(shù)據(jù)過程-創(chuàng)新互聯(lián)

今天就跟大家聊聊有關(guān)如何理解SPRINGBOOT讀取PROPERTIES配置文件數(shù)據(jù)過程,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

專業(yè)成都網(wǎng)站建設(shè)公司,做排名好的好網(wǎng)站,排在同行前面,為您帶來客戶和效益!成都創(chuàng)新互聯(lián)為您提供成都網(wǎng)站建設(shè),五站合一網(wǎng)站設(shè)計制作,服務(wù)好的網(wǎng)站設(shè)計公司,成都網(wǎng)站建設(shè)、網(wǎng)站制作負(fù)責(zé)任的成都網(wǎng)站制作公司!

一.使用@ConfigurationProperties來讀取

1、Coffer entity

@Configuration@ConfigurationProperties(prefix = "coffer")@PropertySource("classpath:config/coffer.properties")public class Coffer {  private String brand;  private Double length;  private Double width;  private Double height;          //省略了get/set方法  private String[] contains;  private ArrayList fruits;  private HashMap map;}

2、Fruit entity

@Configuration@ConfigurationProperties(prefix = "coffer.fruits")@PropertySource("classpath:config/coffer.properties")public class Fruit {  private String fruitName;  private String fruitColor;        //省略了get/set方法 }

3、coffer.properties

coffer.brand=Camelcoffer.length=100.00coffer.width=80.00coffer.height=60.00coffer.contains[0]=Raincoatcoffer.contains[1]=trouserscoffer.contains[2]=hatcoffer.contains[3]=glovecoffer.contains[4]=scarfcoffer.contains[5]=hoodcoffer.fruits[0].fruitName=apricotcoffer.fruits[0].fruitColor=yellowcoffer.fruits[1].fruitName=plumcoffer.fruits[1].fruitColor=greencoffer.fruits[2].fruitName=pineapplecoffer.fruits[2].fruitColor=yellowcoffer.fruits[3].fruitName=watermeloncoffer.fruits[3].fruitColor=greencoffer.fruits[4].fruitName=strawberrycoffer.fruits[4].fruitColor=redcoffer.map.name=xiaomaocoffer.map.age=22coffer.map.gender=female

4、springbootApplicationTest

@SpringBootTestclass SpringbootApplicationTests {  @Autowired  private ApplicationContext ioc;  @Autowired  private Coffer coffer;  @Test  public void springbootTest(){    System.out.println(coffer);  }}

5、result

Coffer{  brand='Camel',   length=100.0,   width=80.0,   height=60.0,   contains=[Raincoat, trousers, hat, glove, scarf, hood],   fruits=[       Fruit{fruitName='apricot', fruitColor='yellow'},        Fruit{fruitName='plum', fruitColor='green'},        Fruit{fruitName='pineapple', fruitColor='yellow'},        Fruit{fruitName='watermelon', fruitColor='green'},        Fruit{fruitName='strawberry', fruitColor='red'}      ],   map={age=22, gender=female, name=xiaomao}}

二、使用@Value來讀取

在springTest中無法使用@Value來讀取配置屬性,需要放到Controller中去讀取

@PropertySource("classpath:config/coffer.properties")@RestControllerpublic class SpringbootController {  @Value("${coffer.brand}")  private String brand;  @Value("${coffer.height}")  private Double height;  @RequestMapping("/test")  public String springbootTest() {    return brand+"====="+height;  }}

看完上述內(nèi)容,你們對如何理解SPRINGBOOT讀取PROPERTIES配置文件數(shù)據(jù)過程有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。


當(dāng)前題目:如何理解SPRINGBOOT讀取PROPERTIES配置文件數(shù)據(jù)過程-創(chuàng)新互聯(lián)
網(wǎng)頁路徑:http://www.dlmjj.cn/article/iccgo.html