基于SPRINGBOOT配置文件占位符過程解析
這篇文章主要介紹了基于SPRINGBOOT配置文件占位符過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
一、配置文件占位符
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' }
二、配置文件獲取之前的值(如果該值有,直接獲取,如果沒有使用默認(rèn)值):此處由于前面的配置中沒有product.name,那么他就使用默認(rèn)值 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ù)進(jìn)行操作(轉(zhuǎn)化,過濾,匯總等),類比Python中的Pandas庫,本文介紹Spring Boot集成tablesaw插件快速入門Demo,感興趣的朋友一起看看吧2024-06-06springboot2.2 集成 activity6實(shí)現(xiàn)請假流程(示例詳解)
這篇文章主要介紹了springboot2.2 集成 activity6實(shí)現(xiàn)請假完整流程示例詳解,本文通過示例代碼圖文相結(jié)合給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07SpringBoot如何進(jìn)行業(yè)務(wù)校驗(yàn)實(shí)例詳解
這篇文章主要給大家介紹了關(guān)于SpringBoot如何進(jìn)行業(yè)務(wù)校驗(yàn)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-01-01MyBatis參數(shù)處理實(shí)現(xiàn)方法匯總
這篇文章主要介紹了MyBatis參數(shù)處理實(shí)現(xiàn)方法匯總,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08Java使用線程實(shí)現(xiàn)異步運(yùn)行的方法
在Java中,實(shí)現(xiàn)異步運(yùn)行的一個(gè)常用方式是使用Thread類,這篇文章主要介紹了Java使用線程實(shí)現(xiàn)異步運(yùn)行,需要的朋友可以參考下2024-07-07spring?boot如何通過自定義注解和AOP攔截指定的請求
這篇文章主要介紹了spring?boot通過自定義注解和AOP攔截指定的請求,本文主要通過切面類和自定注解的方式,攔截指定的接口(代碼中已經(jīng)作了詳細(xì)的說明),需要的朋友可以參考下2024-06-06