Throw in a peach and return it with a courtesy. For those who maliciously brush my interface, I will come to prevent malicious brushing, it is not too much!
First upload a picture to see what this kind of people are doing. There are many such people. They usually do things in the middle of the night. They are all very stupid. They have brains but not many of them!
If you make trouble, I will add you to the blacklist. It is fair. Take a screenshot to see the effect
Users who have been listed in the blacklist visit the website again, and the interface looks like this, not fancy, simple and rude
implement logic
I allow you to deliberately visit the wrong address three times. The first path is error, I set it to jump to 404, the second and third times it jumps to fuck, and the fourth time it is directly printed by the filter and added to the blacklist
- Create an interceptor
public class GlobalInterceptor implements HandlerInterceptor
The interception time can be set according to your own wishes, or it can be set to be permanent, or create a blacklist table and add them to the database, I am lazy here
- Create intercept configuration
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Autowired
private GlobalInterceptor globalInterceptor;
// 对除静态资源外所有路径进行拦截
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry
.addInterceptor(globalInterceptor)
.excludePathPatterns(
"/css/**",
"/js/**",
"/image/**",
"/font/**",
"/icon/**",
"/layui/**",
"/font-awesome/**",
"/editormd/**"
);
}
}
- Cooperate with filter to achieve interception effect
final effect
- first malicious visit
- The second and third times were maliciously accessed
- Finally, directly prompt to join the blacklist