当前位置: 首页 > news >正文

自学免费网站建设ui设计师作品集

自学免费网站建设,ui设计师作品集,淘宝客怎么自己做网站及APP,企业邮箱号1.新建操作类型枚举&#xff08;这里的IEnum是我自定义的http请求拦截接口&#xff0c;不需要的话可以不用实现&#xff09; Getter AllArgsConstructor public enum OperationType implements IEnum<Integer> {/*** 注册*/SIGN_UP(0),/*** 密码登录*/LOGIN_BY_PWD(1),/…

1.新建操作类型枚举(这里的IEnum是我自定义的http请求拦截接口,不需要的话可以不用实现)

@Getter
@AllArgsConstructor
public enum OperationType implements IEnum<Integer> {/*** 注册*/SIGN_UP(0),/*** 密码登录*/LOGIN_BY_PWD(1),/*** 验证码登录*/LOGIN_BY_SMS(2),/*** 忘记密码*/FORGET_PWD(3),/*** 修改密码*/MODIFY_PWD(4);@JsonValueprivate final int code;@Overridepublic Integer getCode(){return code;}
}

2.新建校验注解

@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface SmsValidate {/*** 操作类型* @return*/OperationType operationType() default OperationType.LOGIN_BY_PWD;
}

3.创建验证码校验接口

public interface ISmsValidate {/*** 短信验证码手机号* @return*/String mobile();/*** 短信验证码内容* @return*/String smsCode();
}

4.controller方法请求参数,实现ISmsValidate接口

@Data
public class LoginBySmsDto implements ISmsValidate {@NotBlank(message = "用户名/手机号不能为空")@IsMobileprivate String username;@NotBlank(message = "短信验证码不能为空")private String code;@Overridepublic String mobile() {return this.getUsername();}@Overridepublic String smsCode() {return this.getCode();}
}

5.添加aop切面类

@Aspect
@Component
public class SmsValidateAop {@Autowiredprivate RedisTemplate<String,Object> redisTemplate;@Pointcut(value = "@annotation(com.tfyt.common.annotation.SmsValidate)")public void pointCut(){}@Before(value = "pointCut()")public void before(JoinPoint joinPoint){SmsObj smsObj = getSmsObj(joinPoint);Object cacheCode = redisTemplate.opsForValue().get(RedisKeyConstant.CACHE_SMS_CODE + smsObj.getOperationType() + ":" + smsObj.getMobile());BusinessAssert.notTrue(Objects.equals(cacheCode,smsObj.getCode()),"手机验证码不正确");}@AfterReturning(value = "pointCut()")public void after(JoinPoint joinPoint){SmsObj smsObj = getSmsObj(joinPoint);redisTemplate.delete(RedisKeyConstant.CACHE_SMS_CODE + smsObj.getOperationType() + ":" + smsObj.getMobile());}@Data@AllArgsConstructor@NoArgsConstructorprivate static class SmsObj{private String mobile;private String code;private Integer operationType;}private SmsObj getSmsObj(JoinPoint joinPoint){MethodSignature signature = (MethodSignature) joinPoint.getSignature();SmsValidate annotation = signature.getMethod().getAnnotation(SmsValidate.class);BusinessAssert.isNull(annotation,"系统异常:未查询到注解");BusinessAssert.isNull(annotation.operationType(),"系统异常:未配置操作类型");Object[] args = joinPoint.getArgs();ISmsValidate arg = null;if(args[0] instanceof ISmsValidate){arg = (ISmsValidate) args[0];}BusinessAssert.isNull(arg,"请输入用户名和手机验证码");return new SmsObj(arg.mobile(), arg.smsCode(), annotation.operationType().getCode());}
}

6.往controller的方法上注解

@SmsValidate(operationType = OperationType.LOGIN_BY_SMS)

重启springboot项目,调用接口即可生效,校验通过后会自动删除redis缓存

补一个自定义断言类

public class BusinessAssert {public static void notTrue(boolean condition, String msg){isTrue(!condition, msg);}public static void isTrue(boolean condition, String msg){if(condition){throw new BusinessException(HttpStatus.BAD_REQUEST.value(),msg);}}public static void nonNull(Object object,String msg){if(null!=object){throw new BusinessException(HttpStatus.BAD_REQUEST.value(),msg);}}public static void isNull(Object object,String msg){if(null==object){throw new BusinessException(HttpStatus.BAD_REQUEST.value(),msg);}}public static void isCollectionEmpty(Collection<?> collection,String msg){if(collection == null || collection.isEmpty()){throw new BusinessException(HttpStatus.BAD_REQUEST.value(),msg);}}public static void isCollectionNotEmpty(Collection<?> collection,String msg){if(collection != null && !collection.isEmpty()){throw new BusinessException(HttpStatus.BAD_REQUEST.value(),msg);}}

http://www.yayakq.cn/news/189735/

相关文章:

  • 菏泽建设局网站织梦网站识别
  • 蚌埠市住房建设部网站flash网站引导页
  • 搭建网站软件内部建设网站需要什么条件
  • 俄罗斯门户网站模板网站有利于做seo吗
  • 唐朝网站东莞网站优化效果如何
  • 长沙企业官方网站建设培训机构网站制作
  • 网站主页流动图片怎么做厦门律师网站建设
  • 中通顺昌建设有限公司网站行业网站网址
  • 常州网站制作哪家好区块链开发工程师要求
  • 网站空间续费手机可以做软件开发吗
  • 佛山网站优化指导外贸网站怎么找客户
  • 自学设计的网站有哪些制作图网官网
  • 杭州网站制作哪家好wordpress用户中心插件
  • 性男女做视频网站钢材销售都在哪个网站做
  • 企业做网站都购买域名吗淮安网站优化
  • 上海网站建设科技公司付费软件免费拿
  • 大气网站欣赏太原网络营销网站
  • 基础微网站开发可信赖wordpress目录链接加html
  • 微信手机网站源码西安网站设计建设公司 概况
  • 大规模网站网站制作过程教程
  • 网站开发一键上架淘宝网络营销ppt模板
  • 一个好的网站应该具有什么条件网页设计与制作个人总结
  • c 做网站开发实例启迪网站建设招聘
  • 免费网站seo诊断wordpress如何秒开
  • 做合约交易哪个网站好扬州市规划建设局网站
  • 东莞网站推广建设临汾网络推广
  • 海南省做购房合同网站专业网站运营
  • 有关做生态环境的官方网站电子商务网站设计原理知识点
  • 服务好的网站建设联系人阿里百川 网站开发
  • 微信微网站制作公司交互效果好的移动端网站