Files
mp-java/docs/update_datetime_fields.sh

28 lines
823 B
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 批量更新Java实体类中的时间字段类型
# 将 java.util.Date 替换为 java.time.LocalDateTime
echo "开始批量更新时间字段类型..."
# 获取所有包含Date导入的Java文件
files=$(find src/main/java -name "*.java" -exec grep -l "import java.util.Date" {} \;)
for file in $files; do
echo "处理文件: $file"
# 替换导入语句
sed -i '' 's/import java\.util\.Date;/import java.time.LocalDateTime;/g' "$file"
# 替换字段声明
sed -i '' 's/private Date /private LocalDateTime /g' "$file"
# 移除JsonFormat注解如果存在
sed -i '' '/@JsonFormat(pattern = "yyyy-MM-dd")/d' "$file"
sed -i '' '/@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")/d' "$file"
echo "完成处理: $file"
done
echo "批量更新完成!"