Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
檀越@新空间
spring-study
提交
7506ade4
S
spring-study
项目概览
檀越@新空间
/
spring-study
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-study
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
“6f09801ef97d58ac9a2cc4962edbb812287a9df5”上不存在“projects/coder-hhx/imports.yml”
提交
7506ade4
编写于
3月 22, 2023
作者:
檀越@新空间
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:添加工具类
上级
bb1f4fe8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
165 addition
and
5 deletion
+165
-5
pom.xml
pom.xml
+15
-0
src/main/java/com/kwan/spring5/utils/FileContains.java
src/main/java/com/kwan/spring5/utils/FileContains.java
+150
-0
src/main/resources/spring1.xml
src/main/resources/spring1.xml
+0
-4
src/test/java/Spring_01_BookTest.java
src/test/java/Spring_01_BookTest.java
+0
-1
未找到文件。
pom.xml
浏览文件 @
7506ade4
...
@@ -73,5 +73,20 @@
...
@@ -73,5 +73,20 @@
<version>
5.3.8
</version>
<version>
5.3.8
</version>
<scope>
compile
</scope>
<scope>
compile
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.8.12
</version>
</dependency>
<dependency>
<groupId>
com.alibaba.fastjson2
</groupId>
<artifactId>
fastjson2
</artifactId>
<version>
2.0.23
</version>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
31.1-jre
</version>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
\ No newline at end of file
src/main/java/com/kwan/spring5/utils/FileContains.java
0 → 100644
浏览文件 @
7506ade4
package
com.kwan.spring5.utils
;
import
cn.hutool.core.date.StopWatch
;
import
com.alibaba.fastjson2.JSON
;
import
com.google.common.base.Charsets
;
import
com.google.common.io.Files
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 字符串是否存在文件中
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/2/8 10:45
*/
public
class
FileContains
{
/**
* 默认不存在
*/
private
static
boolean
IS_EXIST
=
false
;
/**
* 图片路径
*/
private
static
final
String
PIC_PATH
=
"/Users/qinyingjie/Documents/idea-workspace/blogimg/"
;
/**
* 博客路径
*/
private
static
final
String
BLOG_FOLDER
=
"/Users/qinyingjie/Documents/idea-workspace/blog/"
;
public
static
void
main
(
String
[]
args
)
throws
IOException
{
StopWatch
stopWatch
=
new
StopWatch
();
stopWatch
.
start
();
final
List
<
String
>
isNotExist
=
new
ArrayList
<>();
//获取picPath下面所有的文件名
final
List
<
String
>
picNames
=
getPicName
(
PIC_PATH
);
System
.
out
.
println
(
"图片总数为"
+
picNames
.
size
());
for
(
String
word
:
picNames
)
{
IS_EXIST
=
false
;
//指定类型的文件
String
suffix
=
".md"
;
//包含某个字符串
traverseFolder
(
BLOG_FOLDER
,
suffix
,
word
);
//文件不存在
if
(!
IS_EXIST
)
{
isNotExist
.
add
(
word
);
deletePic
(
PIC_PATH
+
word
);
}
}
System
.
out
.
println
(
"不存在图片总数为"
+
isNotExist
.
size
());
stopWatch
.
stop
();
//毫秒输出
System
.
out
.
println
(
JSON
.
toJSONString
(
stopWatch
.
getTaskInfo
()));
}
/**
* 获取文件
*
* @param path
* @param suffix
* @param word
* @throws IOException
*/
public
static
void
traverseFolder
(
String
path
,
String
suffix
,
String
word
)
throws
IOException
{
File
file
=
new
File
(
path
);
if
(
file
.
exists
())
{
//获取文件夹下的文件
File
[]
files
=
file
.
listFiles
();
if
(
null
!=
files
&&
files
.
length
!=
0
)
{
for
(
File
file2
:
files
)
{
//是否是文件夹
if
(
file2
.
isDirectory
())
{
traverseFolder
(
file2
.
getAbsolutePath
(),
suffix
,
word
);
}
else
{
//包含md结尾的文件
if
(
file2
.
getAbsolutePath
().
contains
(
suffix
))
{
getParams
(
file2
.
getAbsolutePath
(),
word
);
}
}
}
}
}
}
/**
* 判断文件是否存在
*
* @param classPath
* @param word
* @throws IOException
*/
public
static
void
getParams
(
String
classPath
,
String
word
)
throws
IOException
{
File
file
=
new
File
(
classPath
);
//每行作为一个字符串,存为列表元素
List
<
String
>
strings
=
Files
.
readLines
(
file
,
Charsets
.
UTF_8
);
for
(
String
string
:
strings
)
{
//判断是否包含方法名称,即指定字符串
if
(
string
.
contains
(
word
))
{
//文件存在
IS_EXIST
=
true
;
}
}
}
/**
* 获取图片名称
*
* @param path
* @return
*/
public
static
List
<
String
>
getPicName
(
String
path
)
{
List
<
String
>
picNames
=
new
ArrayList
<>();
File
file
=
new
File
(
path
);
if
(
file
.
exists
())
{
//获取文件夹下的文件
File
[]
files
=
file
.
listFiles
();
if
(
null
!=
files
&&
files
.
length
!=
0
)
{
for
(
File
file2
:
files
)
{
//是否是文件夹
if
(!
file2
.
isDirectory
())
{
//包含md结尾的文件
final
String
name
=
file2
.
getName
();
picNames
.
add
(
name
);
}
}
}
}
return
picNames
;
}
/**
* 删除文件
*
* @param picPath
*/
public
static
void
deletePic
(
String
picPath
)
{
File
file
=
new
File
(
picPath
);
try
{
file
.
delete
();
System
.
out
.
printf
(
"删除文件成功:%s%n"
,
picPath
);
}
catch
(
Exception
e
)
{
System
.
err
.
printf
(
"无法删除的路径 %s%n%s"
,
picPath
,
e
);
}
}
}
\ No newline at end of file
src/main/resources/spring1.xml
浏览文件 @
7506ade4
...
@@ -9,7 +9,6 @@
...
@@ -9,7 +9,6 @@
<context:annotation-config/>
<context:annotation-config/>
<!--注入user类-->
<!--注入user类-->
<bean
id=
"user"
class=
"com.kwan.spring5.User"
></bean>
<bean
id=
"user"
class=
"com.kwan.spring5.User"
></bean>
<!--spring方式: set方法注入属性-->
<!--spring方式: set方法注入属性-->
<bean
id=
"book"
class=
"com.kwan.spring5.Book"
>
<bean
id=
"book"
class=
"com.kwan.spring5.Book"
>
<!--使用property完成属性注入
<!--使用property完成属性注入
...
@@ -19,12 +18,9 @@
...
@@ -19,12 +18,9 @@
<property
name=
"bname"
value=
"Hello"
></property>
<property
name=
"bname"
value=
"Hello"
></property>
<property
name=
"bauthor"
value=
"World"
></property>
<property
name=
"bauthor"
value=
"World"
></property>
</bean>
</bean>
<!--(2)spring方式:有参数构造注入属性-->
<!--(2)spring方式:有参数构造注入属性-->
<bean
id=
"orders"
class=
"com.kwan.spring5.Orders"
>
<bean
id=
"orders"
class=
"com.kwan.spring5.Orders"
>
<constructor-arg
name=
"oname"
value=
"Hello"
></constructor-arg>
<constructor-arg
name=
"oname"
value=
"Hello"
></constructor-arg>
<constructor-arg
name=
"address"
value=
"China!"
></constructor-arg>
<constructor-arg
name=
"address"
value=
"China!"
></constructor-arg>
</bean>
</bean>
</beans>
</beans>
\ No newline at end of file
src/test/java/Spring_01_BookTest.java
浏览文件 @
7506ade4
...
@@ -11,7 +11,6 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
...
@@ -11,7 +11,6 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
* @date : 2022/11/12 18:43
* @date : 2022/11/12 18:43
*/
*/
public
class
Spring_01_BookTest
{
public
class
Spring_01_BookTest
{
@Test
@Test
public
void
test1
()
{
public
void
test1
()
{
ApplicationContext
ctx
=
ApplicationContext
ctx
=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录