一、配置文件占位符

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. 测开之路一百五十五:jquery-validation前台数据验证

    前面做的wtform验证是服务器端的验证,需要把数据传输到服务器,服务器验证后再吧结果传输到前端,网络慢的时候,用户体验不好,所以需要前端验证,且后端验证不能少 传统的js或者jquery如果要验证信 ...

  2. Windows.命令行(CMD)_执行命令&环境变量

    1.CMD命令中如果 命令有换行的话,就使用 ^来连接(这就类似于 Linux命令行中 \ 的作用) 2.环境变量 2.1.显示 所有环境变量的值,命令:set 2.2.显示 某个环境变量的值,命令 ...

  3. .net core 学习小结之 PostMan报415

    首先415的官方解释是:对于当前请求的方法和所请求的资源,请求中提交的实体并不是服务器中所支持的格式,因此请求被拒绝. 也就是说我所准备的数据格式并不是后台代码使用的数据格式 后台代码如下 using ...

  4. [转帖]mysql.sock的作用

    mysql.sock的作用 链接:http://blog.itpub.net/28602568/viewspace-1797619/ 标题:mysql.sock的作用 作者:lōττéry©版权所有[ ...

  5. [19/06/06-星期四] HTML基础_文本标签、列表(有序、无序、定义)、文本格式化(单位、字体、大小写、文本修饰、间距、对齐文本)

    一.文本标签 em:用来表示一段内容的着重点,语气上的强调.一般显示为斜体 i:是斜体显示,和em显示效果一样.h5规定不需要着重的内容而是单纯加粗或斜体可以用i或b.用的不多 strong:用来表示 ...

  6. 秒懂Vuejs、Angular、React原理和前端发展历史

    「前端程序发展的历史」 「 不学自知,不问自晓,古今行事,未之有也 」 我们都知道现在流行的框架:Vue.Js.AngularJs.ReactJs,已经逐渐应用到各个项目和实际应用中,它们都是MVVM ...

  7. springboot工程启动时,报错:No bean named 'shiroFilter' available

    在启动Springboot项目时,报错:org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ' ...

  8. 如何在ubuntu上安装 搜狗输入法(已经成功)

    转自:https://blog.csdn.net/qq_37589838/article/details/81208409 本文链接:https://blog.csdn.net/qq_37589838 ...

  9. Intellij IDEA奇巧妙计(不停更新)

    1,在pom.xml文件中,Ctrl+Shift+Alt+U打开Manven依赖视图 2,Alt+7 查看类里面方法,变量等结构 3, Shift+Esc 收缩编译提示框 4, ctrl+r 替换本页 ...

  10. 数学: HDU1005 Number Sequence

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...