日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

properties随机数与配置文件占位符

發布時間:2025/3/15 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 properties随机数与配置文件占位符 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄

?

理論

例子


理論

RandomValuePropertySource:配置文件中可以使用隨機數

${random.value}、${random.int}、${random.long}、${random.int(10)}、${random.int[1024, 65534]}

?

屬性配置占位符

people.name="你妹" people.alias=${people.name}"呵呵"

?

例子

程序結構如下:

運行截圖如下:

源碼如下:

People.java

package com.setactive.demo.bean;import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;@Component @ConfigurationProperties(prefix = "people") public class People {private String name;private String aliay;private int age;private int weight;private int height;@Overridepublic String toString() {return "People{" +"name='" + name + '\'' +", aliay='" + aliay + '\'' +", age=" + age +", weight=" + weight +", height=" + height +'}';}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAliay() {return aliay;}public void setAliay(String aliay) {this.aliay = aliay;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public int getWeight() {return weight;}public void setWeight(int weight) {this.weight = weight;}public int getHeight() {return height;}public void setHeight(int height) {this.height = height;} }

DemoApplication.java

package com.setactive.demo;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}}

application.properties

people.name="你妹"${random.uuid} people.aliay="日了狗了"${random.uuid} people.height=${random.int} people.weight=${random.int}

DemoApplicationTests.java

package com.setactive.demo;import com.setactive.demo.bean.People; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner;@RunWith(SpringRunner.class) @SpringBootTest public class DemoApplicationTests {@AutowiredPeople people;@Testpublic void contextLoads() {System.out.println(people);}}

修改application.properties文件

#people.name="你妹"${random.uuid} people.aliay=${people.name:呵呵}呵呵噠 people.height=${random.int} people.weight=${random.int}

運行截圖如下:

總結

以上是生活随笔為你收集整理的properties随机数与配置文件占位符的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。