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 ...
随机推荐
- linux(centOS7)的基本操作(二) 目录和文件管理
1.显示当前工作目录的绝对路径 pwd 2.显示当前工作目录下的子目录和文件 ls [-l] [-h] [-a] 如果只调用ls,子目录和文件会简单的罗列出来,-l表示将其以详细列表的形式展示,-h表 ...
- 配置文件pytest.ini
前言 pytest配置文件可以改变pytest的运行方式,它是一个固定的文件pytest.ini文件,读取配置信息,按指定的方式去运行. ini配置文件 pytest里面有些文件是非test文件 py ...
- JavaScript —— 实现简单计算器【带有 开/关机 清零 退格 功能】
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...
- 什么是Shell?Shell脚本基础知识详细介绍
这篇文章主要介绍了什么是Shell?Shell脚本基础知识介绍,本文是一篇Shell脚本入门文章,在本文你可学到什么是Shell.有多少种Shell.一个Shell脚本代码实例,需要的朋友可以参考下 ...
- Nginx 的root和 alias
nginx是通过alias设置虚拟目录,在nginx的配置中,alias目录和root目录是有区别的:1)alias指定的目录是准确的,即location匹配访问的path目录下的文件直接是在alia ...
- Field baseMapper in com.baomidou.mybatisplus.extension.service.impl.ServiceImpl required a single bean, but xx were found:
在学习使用 mybatis-plus 时,遇到一个奇怪的异常 如 代码一: 代码一: Error starting ApplicationContext. To display the conditi ...
- Spark启动流程(Standalone)- master源码
Master源码 package org.apache.spark.deploy.master //伴生类 private[deploy] class Master( override val rpc ...
- linux工具之screen
screen官方网址:http://www.gnu.org/software/screen/ 参考文章:http://man.linuxde.net/screen 简介 Screen是一款由GNU计划 ...
- C++ 中的new、malloc、namespace
1,这些新引入的成员想要解决 C 语言中存在的一些问题, 2,动态内存分配: 1,C++ 中的动态内存分配: 1,C++ 中通过 new 关键字进行基于类型的动态内存申请: 1,C 语言中自身不包含动 ...
- electron实现qq快捷登录!
之前本来想不写这个功能的,结果客户死活要qq登录! 实在没办法就写了,顺便写个文章!在写之前有两个问题:1: 打开qq授权页面点击页面中的链接会又打开一个页面! .....2: 授权之后是否成功很难去 ...