redis不能直接保存localDateTime对象,需要转为String类型,否则从redis中取出再和localDateTime比对是,即使转为localDateTime比对,也会失败。
// 计算文件名的哈希码(注意:这里使用文件名而不是文件路径)
int hashCode = filename.hashCode();
// 获取当前时间
LocalDateTime currentTime = LocalDateTime.now();
Map<String, Map<String, Object>> uploadFilePath = new HashMap<>();
if(redisTemplate.hasKey("upload_file_path")){
uploadFilePath = redisCache.getCacheMap("upload_file_path");
}
// 创建一个 DateTimeFormatter 对象,指定格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 使用 formatter 将 LocalDateTime 转换为 String
String formattedDateTime = currentTime.format(formatter);
// 创建存储对象(使用 HashMap)
Map<String, Object> data = new HashMap<>();
data.put("filepath", filename);
data.put("timestamp", formattedDateTime);
// 使用 HashMap 来存储文件名哈希码到数据的映射

最低0.47元/天 解锁文章
3万+

被折叠的 条评论
为什么被折叠?



