Yaml spring boot 二維數組寫法

Yamljava

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個, 不要用內部類的形式this

@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;
    }
}
相關文章
相關標籤/搜索