class User {
Integer id;
String name;
public User(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class UserQuery {
Integer id;
String name;
public UserQuery() {
}
public UserQuery(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
//转换list对象
userList.clear();
userList.add(new User(3, "Tom3"));
userList.add(new User(2, "Tom2"));
userList.add(new User(1, "Tom1"));
List<UserQuery> userQuerylist = new ArrayList<>();
userList.stream().forEach(user -> {
UserQuery userQuery = new UserQuery();
userQuery.setId(user.getId());
userQuery.setName(user.getName());
userQuerylist.add(userQuery);
});