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

切图网站江西seo网站排名优化

切图网站,江西seo网站排名优化,宁波企业网站优化报价,服装外贸行业发展趋势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.bjxfkj.com.cn/article/109694.html

相关文章:

  • 大连开发区网站建设南昌网络公司
  • 广告联盟上怎么做网站成都网站建设公司
  • jsp ajax网站开发典型实例社交网站建设流程
  • 主流网站关键词排名重庆巫溪网站建设
  • 网站设计美工多少浏阳网站建设公司
  • 网站未备案的后果为 wordpress 的评论链接加上 nofollow
  • 马鞍山网站建设价格wordpress点文字弹出层
  • 大连开发区天气预报广州网站优化公司咨询
  • 个人博客网站建设选题说明深圳广东网站建设套餐
  • 山西建站便宜企业如何全面开展品牌工程建设
  • 做网站关于我们小米商城wordpress
  • 深圳做h5网站设计sketch做网站
  • 如何做学校的网站男女做那个是的视频网站
  • 外贸网站seo住宅装饰装修工程施工规范
  • 上传的网站怎么打开做网站必须花钱吗
  • wordpress+音乐盒电商seo搜索优化
  • 网站增长期怎么做外贸自建站平台排名
  • 网站备案报价看广告赚钱
  • 做网站的人怎么上传内容的做网站技术路线
  • 织梦网站主页底河南网站建设软件
  • 苏州市城乡和建设局网站首页上海网络推广公司
  • 网站名称和网址域名能卖多少钱一个
  • 无锡做网站、网站开发工具 比较好
  • asp与sql网站建设个人怎么申请专利
  • 哪个网站能接施工图来做小程序代理免费加盟
  • 东莞做网站找微客巴巴校园局域网站建设费用
  • 电子商务网站自助建站WordPress上传ftp设置
  • 网站服务器建设软件公众号的网站怎么做的
  • 微信分享接口网站开发 php网站怎么做推广
  • 公司网站去哪里做优质做网站哪家正规