这是一个笔记,方便我忘记后使用。
html,图片进入getCode方法。
<input type="text" placeholder="请输入验证码" autocomplete="off" id="code" name="code" class="layui-input" lay-verify="required">
<img src= "/getCode" onclick="this.src = this.src+'?'">
js
我将code也传入后端,一起放到了SysUser实体类中,定义为String类型。
使用的是hutool依赖,下面定义方法
@RequestMapping("getCode")
public void getCode(HttpServletResponse response, HttpSession session) throws IOException {
//定义图形验证码的长和宽,数的个数,干扰线的条数。
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(116, 33,4,10);
//在session中生成code值