Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
03bade2c
S
SpringBoot-kwan
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringBoot-kwan
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringBoot-kwan
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
03bade2c
编写于
8月 26, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:测试拼音
上级
05e9109c
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
113 addition
and
4 deletion
+113
-4
pom.xml
pom.xml
+5
-0
src/main/java/com/kwan/springbootkwan/filter/CorsFilter.java
src/main/java/com/kwan/springbootkwan/filter/CorsFilter.java
+7
-2
src/main/java/com/kwan/springbootkwan/filter/MyFilter.java
src/main/java/com/kwan/springbootkwan/filter/MyFilter.java
+31
-0
src/main/java/com/kwan/springbootkwan/utils/PinyinUtil.java
src/main/java/com/kwan/springbootkwan/utils/PinyinUtil.java
+49
-0
src/test/java/com/kwan/springbootkwan/UserServiceImplTest.java
...est/java/com/kwan/springbootkwan/UserServiceImplTest.java
+2
-2
src/test/java/com/kwan/springbootkwan/utils/PinyinUtilTest.java
...st/java/com/kwan/springbootkwan/utils/PinyinUtilTest.java
+19
-0
未找到文件。
pom.xml
浏览文件 @
03bade2c
...
@@ -187,6 +187,11 @@
...
@@ -187,6 +187,11 @@
<artifactId>
poi-ooxml
</artifactId>
<artifactId>
poi-ooxml
</artifactId>
<version>
4.1.2
</version>
<version>
4.1.2
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.hankcs
</groupId>
<artifactId>
hanlp
</artifactId>
<version>
portable-1.8.3
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
<plugins>
<plugins>
...
...
src/main/java/com/kwan/springbootkwan/filter/CorsFilter.java
浏览文件 @
03bade2c
package
com.kwan.springbootkwan.filter
;
package
com.kwan.springbootkwan.filter
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.*
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -14,6 +19,7 @@ import java.io.IOException;
...
@@ -14,6 +19,7 @@ import java.io.IOException;
* @version : 2.2.0
* @version : 2.2.0
* @date : 2023/7/9 22:54
* @date : 2023/7/9 22:54
*/
*/
@Order
(
1
)
@Component
@Component
public
class
CorsFilter
implements
Filter
{
public
class
CorsFilter
implements
Filter
{
...
@@ -25,7 +31,6 @@ public class CorsFilter implements Filter {
...
@@ -25,7 +31,6 @@ public class CorsFilter implements Filter {
httpResponse
.
setHeader
(
"Access-Control-Allow-Methods"
,
"GET, POST, PUT, DELETE, OPTIONS"
);
httpResponse
.
setHeader
(
"Access-Control-Allow-Methods"
,
"GET, POST, PUT, DELETE, OPTIONS"
);
httpResponse
.
setHeader
(
"Access-Control-Allow-Headers"
,
"Origin, X-Requested-With, Content-Type, Accept"
);
httpResponse
.
setHeader
(
"Access-Control-Allow-Headers"
,
"Origin, X-Requested-With, Content-Type, Accept"
);
httpResponse
.
setHeader
(
"Access-Control-Allow-Credentials"
,
"true"
);
httpResponse
.
setHeader
(
"Access-Control-Allow-Credentials"
,
"true"
);
chain
.
doFilter
(
request
,
response
);
chain
.
doFilter
(
request
,
response
);
}
}
}
}
src/main/java/com/kwan/springbootkwan/filter/MyFilter.java
0 → 100644
浏览文件 @
03bade2c
package
com.kwan.springbootkwan.filter
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
java.io.IOException
;
/**
* 添加过滤器
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/8/26 11:06
*/
@Component
@Order
(
2
)
// 设置过滤器的优先级为1,值越小,优先级越高
public
class
MyFilter
implements
Filter
{
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
ServletException
{
// 过滤器逻辑
chain
.
doFilter
(
request
,
response
);
}
}
src/main/java/com/kwan/springbootkwan/utils/PinyinUtil.java
0 → 100644
浏览文件 @
03bade2c
package
com.kwan.springbootkwan.utils
;
import
com.hankcs.hanlp.dictionary.py.Pinyin
;
import
com.hankcs.hanlp.dictionary.py.PinyinDictionary
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.util.CollectionUtils
;
import
java.util.List
;
/**
* 拼音工具类
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/8/26 11:16
*/
public
class
PinyinUtil
{
/**
* 获取中文完整拼音
*
* @param chineseStr
* @return
*/
public
static
String
getPinyin
(
String
chineseStr
)
{
List
<
Pinyin
>
pinyins
=
PinyinDictionary
.
convertToPinyin
(
chineseStr
);
StringBuilder
stringBuilder
=
new
StringBuilder
();
for
(
Pinyin
pinyin
:
pinyins
)
{
stringBuilder
.
append
(
pinyin
.
getPinyinWithoutTone
());
}
return
stringBuilder
.
toString
();
}
/**
* 获取中文拼音首字母
*
* @param chineseStr
* @return
*/
public
static
String
getInitial
(
String
chineseStr
)
{
List
<
Pinyin
>
pinyins
=
PinyinDictionary
.
convertToPinyin
(
chineseStr
);
if
(
CollectionUtils
.
isEmpty
(
pinyins
))
{
return
StringUtils
.
EMPTY
;
}
return
String
.
valueOf
(
pinyins
.
get
(
0
).
getPinyinWithoutTone
().
charAt
(
0
));
}
}
src/test/java/com/kwan/springbootkwan/UserServiceImplTest.java
浏览文件 @
03bade2c
...
@@ -5,7 +5,7 @@ import com.kwan.springbootkwan.entity.User;
...
@@ -5,7 +5,7 @@ import com.kwan.springbootkwan.entity.User;
import
com.kwan.springbootkwan.mapper.UserMapper
;
import
com.kwan.springbootkwan.mapper.UserMapper
;
import
com.kwan.springbootkwan.service.ISendMsgHandle
;
import
com.kwan.springbootkwan.service.ISendMsgHandle
;
import
com.kwan.springbootkwan.utils.RedisIdWorker
;
import
com.kwan.springbootkwan.utils.RedisIdWorker
;
import
org.junit.
jupiter.api.
Test
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
...
@@ -129,7 +129,7 @@ public class UserServiceImplTest {
...
@@ -129,7 +129,7 @@ public class UserServiceImplTest {
}
}
latch
.
await
();
latch
.
await
();
long
end
=
System
.
currentTimeMillis
();
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"times = "
+
(
end
-
begin
));
System
.
out
.
println
(
"times = "
+
(
end
-
begin
));
}
}
...
...
src/test/java/com/kwan/springbootkwan/utils/PinyinUtilTest.java
0 → 100644
浏览文件 @
03bade2c
package
com.kwan.springbootkwan.utils
;
import
com.kwan.springbootkwan.SpringBootKwanApplication
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringRunner
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
@ContextConfiguration
(
classes
=
SpringBootKwanApplication
.
class
)
public
class
PinyinUtilTest
{
@Test
public
void
testName
()
{
assert
"ceshi"
.
equals
(
PinyinUtil
.
getPinyin
(
"测试"
));
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录