public ResponseEntity verification(String uuid, HttpServletResponse response) throws IOException {
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(300, 100);
String code = lineCaptcha.getCode();
stringRedisTemplate.opsForValue().set(uuid, code);
lineCaptcha.write(response.getOutputStream());
return ResponseEntity.ok(null);
}
BusinessException
public class BusinessException extends RuntimeException {
public BusinessException(String message){
super(message);
}
}
GlobalExceptionAdvice
@ControllerAdvice
public class GlobalExceptionAdvice {
@ExceptionHandler(Exception.class)
public ResponseEntity handlerException(Exception ex) {
System.out.println(ex.getMessage());
String message = "网络繁忙~~~";
if (ex instanceof BusinessException) {
message = ex.getMessage();
}
return ResponseEntity.status(500).body(message);
}
}