Springboot配置文件占位符
一、配置文件占位符
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'
}
Springboot配置文件占位符的更多相关文章
- 3、springboot配置文件占位符
RandomValuePropertySource:配置文件中可以使用随机数 ${random.value}.${random.int}.${random.long}.${random.int(10) ...
- SpringBoot——配置文件占位符
在配置文件中采用: ${random.int} 获取一个随机值.
- 3springboot:springboot配置文件(配置文件占位符、Profile、配置文件的加载位置)
1.配置文件占位符 RaandomValuePropertySourcr:配置文件可以使用随机数 ${random.value} ${random.int} ${random.long ...
- SpringBoot系列之配置文件占位符使用
SpringBoot系列之配置文件占位符使用 Springboot占位符支持的有随机数和配置的值等等,本博客主要介绍的是随机数和获取属性配置值的简单用法 随机数获取 支持的写法有: ${random. ...
- SpringBoot学习(四)——配置文件占位符
RandomValuePropertySource:配置文件中可以使用随机数 ${Random.value} ${random.int}, ${random.long}, ${random.int( ...
- 聊聊 SpringBoot 中的两种占位符:@*@ 和 ${*}
前言 在 SpringBoot 项目中,我们经常会使用两种占位符(有时候还会混用),它们分别是: @*@ ${*} 如果我们上网搜索「SpringBoot 的占位符 @」,大部分答案会告诉你,Spri ...
- SpringBoot——配置文件详解【五】
前言 SpringBoot的配置文件 配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的. application.properties application.yml 配置文件 ...
- 【SpringBoot】SpringBoot配置文件及YAML简介(三)
SpringBoot配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的; application.properties application.yml 配置文件的作用:修改Spr ...
- SpringBoot配置文件(1)
配置文件 1.配置文件 SpringBoot使用一个全局的配置文件 application.properties application.yml 配置文件名是固定的: 他的作用是修改SpringBoo ...
随机推荐
- 【零售App】—— react/ant design mobile项目爬坑
一.H5制作 - 图片文本的动画效果 bug:打开一个模板,添加图片,添加动画效果,若先选定动画效果,再调节动画时间和延迟时间,则动画和延迟时间没有改变:若先调节动画时间和延迟时间在选定动画效果,则动 ...
- 64位ubuntu下安装ia32-libs
echo "deb http://archive.ubuntu.com/ubuntu/ raring main restricted universe multiverse" &g ...
- ES6正则拓展
字符串的正则方法 字符串对象共有 4 个方法,可以使用正则表达式:match().replace().search()和split(). ES6 将这 4 个方法,在语言内部全部调用RegExp的实例 ...
- 使用 Dom4j 对XML操作!!!
转自:http://blog.csdn.net/redarmy_chen/article/details/12969219 dom4j是一个Java的XML API,类似于jdom,用来读写XML文件 ...
- 中国MOOC_零基础学Java语言_第3周 循环_2数字特征值
2 数字特征值(5分) 题目内容: 对数字求特征值是常用的编码算法,奇偶特征是一种简单的特征值.对于一个整数,从个位开始对每一位数字编号,个位是1号,十位是2号,以此类推.这个整数在第n位上的数字记作 ...
- 求方程x1+x2+x3=15的整数解的数目
求方程x1+x2+x3=15的整数解的数目要求0≤x1≤5,0≤x2≤6,0≤x3≤7.解:令N为全体非负整数解(x1,x2,x3),A1为其中x1≥6的解:y1=x1-6≥0的解:A2为其中x2≥7 ...
- 25. Reverse Nodes in k-Group[H]k个一组翻转链表
题目 Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. ...
- ubuntu/如何启动、关闭和设置ubuntu防火墙
由于LInux原始的防火墙工具iptables过于繁琐,所以ubuntu默认提供了一个基于iptable之上的防火墙工具ufw. ubuntu 9.10默认的便是UFW防火墙,它已经支持界面操作了.在 ...
- 基于opencv简单的图片截取
import xml.etree.ElementTree as ET import os, cv2 from tqdm import tqdm annota_dir = 'C:\\Users\\Adm ...
- springboot无法找到mapper😵
今天在学习springboot的过程中遇到mapper无法找到的问题,困扰了很久