@TedZhou
2020-11-10T03:35:37.000000Z
字数 1128
阅读 627
java spring
kaptcha 是一个图像验证码生成和验证工具,有许多可配置项,可以简单快捷的生成各式各样的验证码,使用起来也很简便。
<dependency><groupId>com.baomidou</groupId><artifactId>kaptcha-spring-boot-starter</artifactId><version>1.1.0</version></dependency>
不加用默认也可
kaptcha:height: 50width: 200content:length: 4source: abcdefghjklmnopqrstuvwxyz23456789space: 2font:color: blackname: Arialsize: 40background-color:from: lightGrayto: whiteborder:enabled: truecolor: blackthickness: 1
import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;import com.baomidou.kaptcha.Kaptcha;@RestController@RequestMapping("/code")public class CodeController {@Autowiredprivate Kaptcha kaptcha;@RequestMapping("/image")void renderImage() {String code = kaptcha.render();System.out.println(code);}@RequestMapping("/valid")boolean validImage(@RequestParam String code) {return kaptcha.validate(code);}}
