版本
SpringBoot 2.6.1 Mybatis-Plus 3.5.3.1 Guava 23.0
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
< project xmlns = " http://maven.apache.org/POM/4.0.0" xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation= " http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion> 4.0.0</ modelVersion> < parent> < groupId> org.springframework.boot</ groupId> < artifactId> spring-boot-starter-parent</ artifactId> < version> 2.6.1</ version> < relativePath/> </ parent> < groupId> com.lichi</ groupId> < artifactId> generator</ artifactId> < version> 0.0.1-SNAPSHOT</ version> < name> generator</ name> < description> generator</ description> < properties> < java.version> 17</ java.version> </ properties> < dependencies> < dependency> < groupId> org.springframework.boot</ groupId> < artifactId> spring-boot-starter-web</ artifactId> </ dependency> < dependency> < groupId> com.google.guava</ groupId> < artifactId> guava</ artifactId> < version> 23.0</ version> </ dependency> < dependency> < groupId> com.baomidou</ groupId> < artifactId> mybatis-plus-boot-starter</ artifactId> < version> 3.5.1</ version> </ dependency> < dependency> < groupId> com.baomidou</ groupId> < artifactId> mybatis-plus</ artifactId> < version> 3.5.3.1</ version> </ dependency> < dependency> < groupId> com.baomidou</ groupId> < artifactId> mybatis-plus-generator</ artifactId> < version> 3.5.3.1</ version> </ dependency> < dependency> < groupId> mysql</ groupId> < artifactId> mysql-connector-java</ artifactId> < version> 8.0.17</ version> </ dependency> < dependency> < groupId> org.springframework.boot</ groupId> < artifactId> spring-boot-starter-data-redis</ artifactId> </ dependency> < dependency> < groupId> org.freemarker</ groupId> < artifactId> freemarker</ artifactId> < version> 2.3.32</ version> </ dependency> < dependency> < groupId> io.springfox</ groupId> < artifactId> springfox-swagger2</ artifactId> < version> 2.9.2</ version> </ dependency> < dependency> < groupId> io.springfox</ groupId> < artifactId> springfox-swagger-ui</ artifactId> < version> 2.9.2</ version> </ dependency> < dependency> < groupId> org.springframework.boot</ groupId> < artifactId> spring-boot-starter-test</ artifactId> < scope> test</ scope> </ dependency> </ dependencies> < build> < plugins> < plugin> < groupId> org.springframework.boot</ groupId> < artifactId> spring-boot-maven-plugin</ artifactId> </ plugin> </ plugins> </ build> < repositories> < repository> < id> spring-milestones</ id> < name> Spring Milestones</ name> < url> https://repo.spring.io/milestone</ url> < snapshots> < enabled> false</ enabled> </ snapshots> </ repository> < repository> < id> spring-snapshots</ id> < name> Spring Snapshots</ name> < url> https://repo.spring.io/snapshot</ url> < releases> < enabled> false</ enabled> </ releases> </ repository> </ repositories> < pluginRepositories> < pluginRepository> < id> spring-milestones</ id> < name> Spring Milestones</ name> < url> https://repo.spring.io/milestone</ url> < snapshots> < enabled> false</ enabled> </ snapshots> </ pluginRepository> < pluginRepository> < id> spring-snapshots</ id> < name> Spring Snapshots</ name> < url> https://repo.spring.io/snapshot</ url> < releases> < enabled> false</ enabled> </ releases> </ pluginRepository> </ pluginRepositories> </ project>
application.yml
spring : datasource : driver-class-name : com.mysql.cj.jdbc.Driverurl : jdbc: mysql: //ip地址: 3306/ai_room? serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&useSSL=true username : rootpassword : 密码redis : cluster : nodes : - ip地址: 6381 - ip地址: 6382 - ip地址: 6383 - ip地址: 6384 - ip地址: 6385 - ip地址: 6386 max-redirects : 3 password : 111111 lettuce : cluster : refresh : adaptive : true period : 2000 pool : max-active : 8 max-wait : - 1msmax-idle : 10 min-idle : 5 mvc : path match : matching-strategy : ant_path_matchermybatis-plus : mapper-locations : classpath: mapper/*.xml type-aliases-package : com.lichi.generator.entity
布隆过滤器核心代码
public static final BloomFilter < String > bloomFilter = BloomFilter . create ( Funnels . stringFunnel ( Charset . defaultCharset ( ) ) , 100 , 0.03 ) ; bloomFilter. put ( id) ;
@ApiOperation ( "查询用户" ) @ResponseBody @GetMapping ( "/get/{id}" ) public User get ( @PathVariable ( "id" ) String id) { Boolean flag = bloomFilter. mightContain ( id) ; if ( flag) { System . out. println ( "==========布隆过滤器判断可能存在==========" ) ; User user = ( User ) redisTemplate. opsForValue ( ) . get ( userKey + id) ; if ( user == null ) { user = userService. getById ( id) ; if ( user != null ) { redisTemplate. opsForValue ( ) . set ( userKey + id, user) ; } } return user; } System . out. println ( "==========布隆过滤器判断不存在,可疑非法攻击==========" ) ; return null ; }