先看页面,点击验证码图片可以进行切换验证码
验证码利用的HuTool工具
先在pom.xml中添加HuTool依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.5.1</version>
</dependency>
生成随机验证码,这里我写了封装类所以返回的Result
@Override
public Result imgCode(){
// 利用 hutool 工具,生成验片资源
CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(200, 100, 4, 7);
// 获得生成的验证码字符
String code = captcha.getCode();
System.out.println("真实的验证码是:"+code);
request.getSession().setAttribute("code",code);
// 将验证码图片的二进制数据写入【响应体 response 】
try {
captcha.write(response.getOutputStream());
} catch (IOExce