上一节:SpringBoot开发笔记-(5)-导入外部资源: @ImportResource


6.1 随机数

${random.value}

${random.int}

${random.long}

${random.uuid} : 随机uuid字符串;

${random.int(10)} : 从0-10中的一个随机数;

${random.int[10,20]} : 从10到20中间的一个随机数, 注: 经过测试, 10和20中间还不能有空格, 否则无效!

6.2 如果没有,指定默认值:

${person.lastName:无名}

person:
  lastName: ${random.uuid}
  age: ${random.int(100)}
  male: true
  birth: 1985/03/03
  maps: {k1: v1, k2: 20, k3: true}
  lists:
    - lisi
    - wangwu
  dog:
    name: ${person.lastName:无名}_小黄
    age: ${random.int[10,20]}
{"lastName":"dffc65aa-8d1b-4110-ada5-debcf59d199b","age":98,"male":true,"birth":"Mar 3, 1985 12:00:00 AM","maps":{"k1":"v1","k2":20,"k3":true},"lists":["lisi","wangwu"],"dog":{"name":"34c4bf97-2885-4a61-b0e6-f9fb176fc86f_小黄","age":11}}

如果把lastName->firstName, 找不到此字段, 就会使用默认值: "无名"

  dog:
    name: ${person.firstName:无名}_小黄
{"lastName":"6ea9265a-a0a2-45cf-bdde-95fbd71305cf","age":39,"male":true,"birth":"Mar 3, 1985 12:00:00 AM","maps":{"k1":"v1","k2":20,"k3":true},"lists":["lisi","wangwu"],"dog":{"name":"无名_小黄","age":17}}

丰木
322 声望19 粉丝

遇见超乎想象的自己!