【Yaml spring boot 二维数组写法】

channel:
  info:
    - channel-ip: 192.168.1.40
      channel-no: 5182001001
    - channel-ip: 192.168.1.10
      channel-no: 5182000002
    - channel-ip: 192.168.1.30
      channel-no: 5182001003
    - channel-ip: 192.168.1.20
      channel-no: 5182000004

JavaBean: 分2个, 不要用内部类的形式 

@Component
@Order(value = 1)
@ConfigurationProperties(prefix = "channel")
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class ChannelProperties {
 
    private List<ChannelInfoPreperties> info = new ArrayList<>();
 
    public List<ChannelInfoPreperties> getInfo() {
        return info;
    }
 
    public void setInfo(List<ChannelInfoPreperties> info) {
        this.info = info;
    }
 
}
@Component
@Order(value = 1)
@ConfigurationProperties(prefix = "channel.info")
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class ChannelInfoPreperties {
 
    private String channelIp;
    private String channelNo;
 
    public String getChannelIp() {
        return channelIp;
    }
 
    public void setChannelIp(String channelIp) {
        this.channelIp = channelIp;
    }
 
    public String getChannelNo() {
        return channelNo;
    }
 
    public void setChannelNo(String channelNo) {
        this.channelNo = channelNo;
    }
}
application:
  gates:
    - name: A
      lanes:
        - A01
        - A03
    - name: B
      lanes:
        - B01
        - B02
@Component
@ConfigurationProperties(prefix = "application")
@Setter
@Getter
@Slf4j
public class GateInfoConfig {
    private List<GateInfo> gates = new ArrayList<>();

    @Setter
    @Getter
    @ToString
    public static class GateInfo {

        private String name;
        private String[] lanes;
    }
}

此方案中yml的名字需要与bean的属性名一致,如例子中的 gates、name、lanes 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值