java开发中常见的工具类,方法等(持续更新)
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |
1.获取当前线程用户信息
/** * 工具类向threadLocal存储诗句 */ public class UserHolder { private static ThreadLocal<User> t1 =new ThreadLocal<>(); //将用户对象存入 public static void set(User user){ t1.set(user); } //当前线程获取用户对象 public static User get(){ return t1.get(); } //当前线程获取用户id public static Long getUserId(){ return t1.get().getId(); } //获取当前用户手机号 public static String getMobile(){ return t1.get().getMobile(); } public static void remove(){ t1.remove(); } }
2.获取list<user>集合中的id集合:
//先判断users集合是否为空
if(!CollUtil.isEmpty(users)){
List<Long> userIds = CollUtil.getFieldValues(users, "userId", Long.class);
}
3.拷贝内容到具有相同成员变量的类中
BeanUtils.copyProperties(item, vo);//将item内容拷贝到新建的vo对象中