yaml数组对象

1、yaml的数组对象配置

com:
 userList:
    list:
    - {id: 1,name: 张三,age: 12}
    - {id: 2,name: 李四,age: 13}

2、java端代码定义,配置为spring注解

public class Users {

	private User[] users={};

	public Users() {
		super();
	}

	public Users(User[] users) {
		super();
		this.users = users;
	}

	public User[] getUsers() {
		return users;
	}

	public void setUsers(User[] users) {
		this.users = users;
	}
}
@Configuration
@ConfigurationProperties("com.userList")
public class UserList {

	private List list=new ArrayList();
	

	public UserList() {
		super();
	}

	public UserList(List list) {
		super();
		this.list = list;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}
	
}

3、注意

  • spring ,使用@ConfigurationProperties注入对象,@value不能很好的解析复杂对象。
  • 定义数组或list时,将其进行初始化。如果不初始化,取到将会是null。

 

你可能感兴趣的:(yaml数组对象)