洪城义警-正式版后台
zengh
2021-11-04 ca7229f26ca62537b1e6242fee975262b60a5ed3
敏感词筛选添加
2 files modified
48 ■■■■■ changed files
src/main/java/org/springblade/modules/article/controller/ArticleController.java 9 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/words/DemoApplication.java 39 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/article/controller/ArticleController.java
@@ -12,12 +12,11 @@
import org.springblade.modules.article.entity.Article;
import org.springblade.modules.article.service.ArticleService;
import org.springblade.modules.article.vo.ArticleVo;
import org.springblade.modules.words.DemoApplication;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
/**
@@ -151,6 +150,12 @@
                article.setCreateTime(new Date());
            }
        }
        if (article.getContent() != null && article.getContent() != ""){
            String content = "";
            content = DemoApplication.interceptWords(article.getContent());
            article.setContent(content);
        }
        article.setUpdateTime(new Date());
        return R.status(articleService.saveOrUpdate(article));
    }
src/main/java/org/springblade/modules/words/DemoApplication.java
@@ -55,7 +55,44 @@
//        test_issues_74();
    }
    private static void test_StringSearch() {
    public static String interceptWords(String content) {
        List<String> list = new ArrayList<String>();
        list.add("美国");
        list.add("日本");
        System.out.println("StringSearch run Test.");
        StringSearch iwords = new StringSearch();
        iwords.SetKeywords(list);
//        boolean b = iwords.ContainsAny(test);
//        if (b == false) {
//            System.out.println("ContainsAny is Error.");
//        }
//
//        String f = iwords.FindFirst(test);
//        if (f != "中国") {
//            System.out.println("FindFirst is Error.");
//        }
//
//        List<String> all = iwords.FindAll(test);
//        if (all.get(0) != "中国") {
//            System.out.println("FindAll is Error.");
//        }
//        if (all.get(1) != "国人") {
//            System.out.println("FindAll is Error.");
//        }
//        if (all.size() != 2) {
//            System.out.println("FindAll is Error.");
//        }
        String str = iwords.Replace(content, '*');
        if (str.equals("我是***") == false) {
            System.out.println("Replace is Error.");
        }
        return str;
    }
    public static void test_StringSearch() {
        String test = "我是中国人";
        List<String> list = new ArrayList<String>();
        list.add("中国");