真香!推荐一个超级简单 Java 图形验证码模块

Java经验总结

共 972字,需浏览 2分钟

 ·

2021-10-23 08:51

来源于网络

简介

Java 图形验证码,支持 Gif、中文、算术等类型,可用于 Java Web、JavaSE 等项目。

效果展示

集成项目

maven 方式引入:



com.github.whvcse
easy-captcha
1.6.2



在 SpringBoot 中使用

@Controller
public class CaptchaController {

@RequestMapping("/captcha")
public void captcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
CaptchaUtil.out(request, response);
}
}

前端 html 代码:

"/captcha" width="130px" height="48px" />

判断验证码是否正确:

@Controller
public class LoginController {

@PostMapping("/login")
public JsonResult login(String username,String password,String verCode){
if (!CaptchaUtil.ver(verCode, request)) {
CaptchaUtil.clear(request); // 清除session中的验证码
return JsonResult.error("验证码不正确");
}
}
}

源码:https://gitee.com/whvse/EasyCaptcha

演示

地址:https://tools.cloudbed.vip

小结

超级简单,种类丰富,支持多种接入方式,推荐给各位小伙伴!

浏览 19
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报