Apache Commons
Apache Commons有很多子项目,常用的项目如下
@Data
public class User {
private String username;
private String password;
}
设置和获得属性
User user = new User();
BeanUtils.setProperty(user, "username", "li");
BeanUtils.getProperty(user, "username");
map和bean的互相转换
// bean->map
Map map = BeanUtils.describe(user);
// map->bean
BeanUtils.populate(user, map);
我们将对象放在缓存中通常用redis中的hash,如下
# 设置用户信息
hset student name test
hset student age 10
这种场景下map和be