一、配置文件占位符

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配置文件占位符的更多相关文章

  1. 3、springboot配置文件占位符

    RandomValuePropertySource:配置文件中可以使用随机数 ${random.value}.${random.int}.${random.long}.${random.int(10) ...

  2. SpringBoot——配置文件占位符

    在配置文件中采用: ${random.int} 获取一个随机值.

  3. 3springboot:springboot配置文件(配置文件占位符、Profile、配置文件的加载位置)

    1.配置文件占位符 RaandomValuePropertySourcr:配置文件可以使用随机数     ${random.value}    ${random.int}  ${random.long ...

  4. SpringBoot系列之配置文件占位符使用

    SpringBoot系列之配置文件占位符使用 Springboot占位符支持的有随机数和配置的值等等,本博客主要介绍的是随机数和获取属性配置值的简单用法 随机数获取 支持的写法有: ${random. ...

  5. SpringBoot学习(四)——配置文件占位符

    RandomValuePropertySource:配置文件中可以使用随机数 ${Random.value}  ${random.int}, ${random.long}, ${random.int( ...

  6. 聊聊 SpringBoot 中的两种占位符:@*@ 和 ${*}

    前言 在 SpringBoot 项目中,我们经常会使用两种占位符(有时候还会混用),它们分别是: @*@ ${*} 如果我们上网搜索「SpringBoot 的占位符 @」,大部分答案会告诉你,Spri ...

  7. SpringBoot——配置文件详解【五】

    前言 SpringBoot的配置文件 配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的. application.properties application.yml 配置文件 ...

  8. 【SpringBoot】SpringBoot配置文件及YAML简介(三)

    SpringBoot配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的; application.properties application.yml 配置文件的作用:修改Spr ...

  9. SpringBoot配置文件(1)

    配置文件 1.配置文件 SpringBoot使用一个全局的配置文件 application.properties application.yml 配置文件名是固定的: 他的作用是修改SpringBoo ...

随机推荐

  1. SQL语句多个字段排序

    写在前面的话: 本次迭代,分配的任务有点多啊,好在本妈妈朝10晚6的加班加点.其中一项就是列表展示啊, 展示就展示呗,还要排序.排序也可以,测试时排序字段值为啥都一样啊.结果点一下一个顺序. 就想在第 ...

  2. MyRocks安装部署

    参考:https://www.cnblogs.com/WonderHow/p/5621591.html CentOS 7.3 gflags:git clone https://github.com/g ...

  3. sklearn系列之 sklearn.svm.SVC详解

    首先我们应该对SVM的参数有一个详细的认知: sklearn.svm.SVC 参数说明: 本身这个函数也是基于libsvm实现的,所以在参数设置上有很多相似的地方.(PS: libsvm中的二次规划问 ...

  4. 4、Shiro之IniRealm以及用户登录认证,角色认证,权限认证

    1.我们在项目test文件夹下面新建resourse文件夹并将她设置为资源文件夹: 2.在resourse文件夹下面新建user.ini文件 user.ini文件里面声明一个用户: 先写一个用户标签[ ...

  5. Git-Runoob:Git 工作区、暂存区和版本库

    ylbtech-Git-Runoob:Git 工作区.暂存区和版本库 1.返回顶部 1. Git 工作区.暂存区和版本库 基本概念 我们先来理解下Git 工作区.暂存区和版本库概念 工作区:就是你在电 ...

  6. JavaScript基础篇详解

    全部的数据类型: 基本数据类型: undefined Number Boolean null String 复杂数据类型: object ①Undefined: >>>声明但未初始化 ...

  7. 【漏洞复现】局域网 ARP 中间人攻击 获取他人账号密码

    日期:2019-07-18 14:24:42 更新: 作者:Bay0net 介绍:如何在局域网内,窃取其他用户的账号密码? 0x01. 漏洞环境 攻击工具 arpspoof 基本用法: arpspoo ...

  8. jmeter线程组基本设置

    线程组基本设置 在线程组界面中可以设置以下数据,进行控制线程组: 1.取样器错误后要执行的动作: 继续:忽略错误,继续执行 Start Next Thread Loop: 忽略错误,线程当前循环终止, ...

  9. 【MM系列】MB1A MB1B MB1C MB11 MIGO的区别解析

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]MB1A MB1B MB1C MB1 ...

  10. servlet3.0文件上传与下载

    描述:文件上传与下载是在JavaEE中常见的功能,实现文件上传与下载的方式有多种,其中文件上传的方式有: (1)commons-fileupload: (2)Servlet 3.0 实现文件上传 (3 ...