1、导入dependency
<dependency>
<groupId>com.github.whvcse</groupId>
<artifactId>easy-captcha</artifactId>
<version>1.6.2</version>
</dependency>
2、测试类
@GetMapping("/captcha")
public ResponseResult getCaptcha(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("image/gif");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 5);
specCaptcha.setFont(new Font("Verdana", Font.PLAIN, 32));
specCaptcha.setCharType(Captcha.TYPE_ONLY_CHAR);
request.getSession().setAttribute("captcha", specCaptcha.text().toLowerCase());
specCaptcha.out(response.getOutputStream());
return null;
}
3、验证
|