kaptcha-spring-boot-starter验证码快速启动器
kaptcha-spring-boot-starter 基于 springBoot2.0 和 Google Kaptcha 的验证码组件,kaptcha-spring-boot-starter 可以很方便的集成验证码到你的系统中。
如何使用
引入 kaptcha-datasource-spring-boot-starter。
<dependency> <groupId>com.baomidou</groupId> <artifactId>kaptcha-spring-boot-starter</artifactId> <version>1.0.0</version> </dependency>
在Controller使用Kaptcha
@RestController @RequestMapping("/kaptcha") public class KaptchaController { @Autowired private Kaptcha kaptcha; @GetMapping("/render") public void render() { kaptcha.render(); } @PostMapping("/valid") public void validDefaultTime(@RequestParam String code) { //default timeout 900 seconds kaptcha.validate(code); } @PostMapping("/validTime") public void validWithTime(@RequestParam String code) { kaptcha.validate(code, 60); } }
发生错误会抛出异常,建议使用全局异常来处理。
KaptchaException //super Exception KaptchaIncorrectException KaptchaNotFoundException KaptchaTimeoutException KaptchaRenderException //If something is wrong then Image.write when render.
import com.baomidou.kaptcha.exception.KaptchaException; import com.baomidou.kaptcha.exception.KaptchaIncorrectException; import com.baomidou.kaptcha.exception.KaptchaNotFoundException; import com.baomidou.kaptcha.exception.KaptchaTimeoutException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @RestControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(value = KaptchaException.class) public String kaptchaExceptionHandler(KaptchaException kaptchaException) { if (kaptchaException instanceof KaptchaIncorrectException) { return "验证码不正确"; } else if (kaptchaException instanceof KaptchaNotFoundException) { return "验证码未找到"; } else if (kaptchaException instanceof KaptchaTimeoutException) { return "验证码过期"; } else { return "验证码渲染失败"; } } }
自定义验证码参数,以下为默认配置。
kaptcha: height: 50 width: 200 content: length: 4 source: abcdefghjklmnopqrstuvwxyz23456789 space: 2 font: color: black name: Arial size: 40 background-color: from: lightGray to: white border: enabled: true color: black thickness: 1
评论
Runner应用程序快速启动器
Runner是一个简单的X11图形环境下的应用程序启动器。具有菜单和启动对话框等方式,快速启动软件。支持输入自动完成和命令匹配推荐(基于历史命令或者$PATH环境变量所指示的可用命令)。上几张截图:从
Runner应用程序快速启动器
0
Alawalk超轻快速启动器
alawalk是一个很小、轻量级的快速程序启动器。目前发布了0.4.1版本新增功能和插件如下:代码清理自带更多的插件默认固定窗口大小使用xterm取代x-terminal-emulator大多数插件更
Alawalk超轻快速启动器
0
RK GRPCgRPC-golang 的快速启动器
rk-grpc是提供gRPC-golang 框架中间件以及快速启动器,可以通过YAML文件的形式,快速启动gRPC-golang 框架微服务。提供的功能功能描述通过YAML启动服务用户可以通过定义YA
RK GRPCgRPC-golang 的快速启动器
0
RK GRPCgRPC-golang 的快速启动器
rk-grpc 是提供 gRPC-golang 框架中间件以及快速启动器,可以通过 YAML 文件的
RK GRPCgRPC-golang 的快速启动器
0