使用工具包生成图片验证码

1.引入依赖


    cn.hutool
    hutool-all
    5.4.3

2.代码集成

//获取验证码图片
@GetMapping("/verification")
public void verification(String uuid,HttpServletResponse response) throws IOException {
    //生成验证码对象
    LineCaptcha captcha = CaptchaUtil.createLineCaptcha(299, 97);
    //将验证码存入redis
    String code = captcha.getCode();
    redisTemplate.opsForValue().set(Constants.CAP_CODE+uuid,code);
    //生成验证码图片
    captcha.write(response.getOutputStream());
}

你可能感兴趣的:(java,前端,服务器,spring,boot)