代码拉取完成,页面将自动刷新
Spring实现请求参数敏感词校验,使用Aho–Corasick作为检测算法 项目采用Kotlin实现
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
// 低版本gradle使用
// compile 'com.github.shenluw.spring-nsfn-validation-starter:nsfn-validation-starter:Tag'
// 版本号查看仓库tag
implementation 'com.github.shenluw.spring-nsfn-validation-starter:nsfn-validation-starter:Tag'
}
@RestController
@Validated
class TestController {
@RequestMapping("/simple")
fun test(@Sensitive text: CharSequence?): CharSequence? {
log.info("simple: {}", text)
return text
}
}
在application.yaml中添加配置,敏感词读取优先级 words > word-file > word-dir
nsfn:
words: 敏感词,敏感
word-file: filepath # 敏感词文件路径,一行表示一个词
word-dir: filedir # 敏感词目录,会读取目录下所有文件内容
也可以自己配置WordStore作为Bean,也可以自定义实现WordStore类,添加不同敏感词的读取策略
@Bean
fun customStore(): MemoryWordStore {
return MemoryWordStore(hashSetOf("word"))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。