Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 如何在yml中为某些属性保持相同的值?_Spring Boot_Yaml - Fatal编程技术网

Spring boot 如何在yml中为某些属性保持相同的值?

Spring boot 如何在yml中为某些属性保持相同的值?,spring-boot,yaml,Spring Boot,Yaml,我可以使用相同的值保留以下子属性。但我想优化 property: bike: ['brake', 'wheel'] car: ['brake', 'wheel'] van: ['brake', 'wheel'] bus: ['brake', 'wheel'] 我想要下面这样的东西,这是我的想法 考虑无断路开关的情况。我刚刚写了一个模型。不要想语法 switch(expression){ bike: car:

我可以使用相同的值保留以下子属性。但我想优化

property:
      bike: ['brake', 'wheel']
      car: ['brake', 'wheel']
      van: ['brake', 'wheel']
      bus: ['brake', 'wheel']
我想要下面这样的东西,这是我的想法

考虑无断路开关的情况。我刚刚写了一个模型。不要想语法

switch(expression){
         bike:
         car:
         van:
               ['brake', 'wheel']
               break;
    }
若将来需要为案例2添加任何内容,我将在案例内部间歇性地添加。因此,案例2是独立的,可以添加更多的值,如

 switch(expression){
         bike:
         car:
               ['brake', 'wheel','with or without gear']
               break;
         van:
               ['brake', 'wheel']
               break;
        }

以上是我的想法。这在yml中可能支持,也可能不支持。我想要与上面类似的东西,或者建议任何其他最佳方式。

您可以使用锚和别名:

property:
  bike: &a [break, wheel]
  car: *a
  van: *a
  bus: *a
但是请注意,这表示对同一对象的多个引用,并不复制给定列表。根据加载YAML后的操作,这可能是您想要的,也可能不是