在网上看到一个很方便的验证码插件:easy-captcha 。使用效果如下。
使用步骤:
1.导入依赖
<!--图形验证码-->
<dependency>
<groupId>com.github.whvcse</groupId>
<artifactId>easy-captcha</artifactId>
<version>1.6.2</version>
</dependency>
2.后端生成验证码并输出给前端(前端加载时请求此接口)
@ApiOperation(value = "获取验证码")
@RequestMapping("v1/captcha")
public void captcha(javax.servlet.http.HttpServletRequest request, HttpServletResponse response) throws Exception {
// 设置请求头为输出图片类型
response.setContentType("image/gif");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-ca