基于SPRINGBOOT配置文件占位符過程解析
這篇文章主要介紹了基于SPRINGBOOT配置文件占位符過程解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
一、配置文件占位符
1、application.properties
server.port=8088
debug=false
product.id=ID:${random.uuid}
product.name=da mao mao
product.weight=${random.int}
product.fristLinePrice=${random.int(500,600)}
product.endLinePrice=${random.int[300,400]}
product.remark=${product.name}
2、SpringbootController
@RestController
public class SpringBootController {
@Value("${product.id}")
private String id;
@Value("${product.name}")
private String name;
@Value("${product.weight}")
private Integer weight;
@Value("${product.fristLinePrice}")
private Integer fristLinePrice;
@Value("${product.endLinePrice}")
private Integer endLinePrice;
@Value("${product.remark}")
private String remark;
@RequestMapping("/proper")
public String getProper() {
System.out.println("SpringBootController{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", weight=" + weight +
", fristLinePrice=" + fristLinePrice +
", endLinePrice=" + endLinePrice +
", remark='" + remark + '\'' +
'}');
return "hello!!!";
}
}
3、result
SpringBootController{
id='ID:188b528a-508f-44aa-9b5e-43c1af7b14e3',
name='da mao mao',
weight=237719179,
fristLinePrice=572,
endLinePrice=380,
remark='da mao mao'
}
二、配置文件獲取之前的值(如果該值有,直接獲取,如果沒有使用默認值):此處由于前面的配置中沒有product.name,那么他就使用默認值 xiao mao mao
server.port=8088
debug=false
product.id=ID:${random.uuid}
product.weight=${random.int}
product.fristLinePrice=${random.int(500,600)}
product.endLinePrice=${random.int[300,400]}
product.remark=${product.name:xiao mao mao}
SpringBootController{
id='ID:fcf731f3-c028-452a-a831-a25c1bf41d33',
name='null',
weight=-1450910103,
fristLinePrice=584,
endLinePrice=357,
remark='xiao mao mao'
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Spring Boot集成tablesaw插件快速入門示例代碼
Tablesaw是一款Java的數(shù)據(jù)可視化庫,數(shù)據(jù)解析庫,主要用于加載數(shù)據(jù),對數(shù)據(jù)進行操作(轉(zhuǎn)化,過濾,匯總等),類比Python中的Pandas庫,本文介紹Spring Boot集成tablesaw插件快速入門Demo,感興趣的朋友一起看看吧2024-06-06
springboot2.2 集成 activity6實現(xiàn)請假流程(示例詳解)
這篇文章主要介紹了springboot2.2 集成 activity6實現(xiàn)請假完整流程示例詳解,本文通過示例代碼圖文相結(jié)合給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-07
SpringBoot如何進行業(yè)務(wù)校驗實例詳解
這篇文章主要給大家介紹了關(guān)于SpringBoot如何進行業(yè)務(wù)校驗的相關(guān)資料,文中通過實例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2022-01-01
spring?boot如何通過自定義注解和AOP攔截指定的請求
這篇文章主要介紹了spring?boot通過自定義注解和AOP攔截指定的請求,本文主要通過切面類和自定注解的方式,攔截指定的接口(代碼中已經(jīng)作了詳細的說明),需要的朋友可以參考下2024-06-06

