fix: 使用SensitiveWordBs替代旧Helper导入
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.test.musichouduan.service.impl;
|
||||
|
||||
import com.github.houbb.sensitive.word.core.SensitiveWordHelper;
|
||||
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
|
||||
import com.test.musichouduan.exception.BusinessException;
|
||||
import com.test.musichouduan.service.SensitiveWordService;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -13,6 +13,12 @@ import java.util.List;
|
||||
@Service
|
||||
public class SensitiveWordServiceImpl implements SensitiveWordService {
|
||||
|
||||
/**
|
||||
* 使用 SensitiveWordBs 初始化敏感词引擎。
|
||||
* 说明:当前依赖版本下推荐使用该入口,避免旧版 Helper 类路径变更导致编译失败。
|
||||
*/
|
||||
private static final SensitiveWordBs SENSITIVE_WORD_BS = SensitiveWordBs.newInstance().init();
|
||||
|
||||
@Override
|
||||
public void validateCommentContent(String content) {
|
||||
if (content == null || content.trim().isEmpty()) {
|
||||
@@ -22,8 +28,8 @@ public class SensitiveWordServiceImpl implements SensitiveWordService {
|
||||
// 使用 houbb/sensitive-word 默认内置词库进行检测。
|
||||
// 当前项目保留了 sensitive-words.txt 作为后续扩展词库参考文件,
|
||||
// 现阶段未主动加载,避免与默认词库机制产生混淆。
|
||||
if (SensitiveWordHelper.contains(content)) {
|
||||
List<String> hitWords = SensitiveWordHelper.findAll(content);
|
||||
if (SENSITIVE_WORD_BS.contains(content)) {
|
||||
List<String> hitWords = SENSITIVE_WORD_BS.findAll(content);
|
||||
if (!hitWords.isEmpty()) {
|
||||
throw new BusinessException("评论包含敏感词,请修改后再发布");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user