Springboot yaml 存放对象数组、map

yaml

user-map:
  maps: {
    admin:
     {username: 'admin',password: '123456',node_id: '1',node_name: '集团'},
    dianchegongsi2:
      {username: 'yifengongsi',password: '123456',node_id: '9',node_name: '一分公司'}
  }
   userList:
    - username: yigongsi2
      password: yigongsi123
      node_id: 4

config

@Component
@Data
@ConfigurationProperties(prefix = "user-map")
public class DataConfig {
    private Map maps;

    private List userList;
}

user

@Data
public class User {

    private String username;

    private String password;

    private Integer nodeId;

    private String nodeName;
}

获取

 @Autowired
    private DataConfig dataConfig;

   Map userMap = dataConfig.getMaps();
   List userList = dataConfig.getUserList();

你可能感兴趣的:(java)