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

网站开发 保密期限百度sem认证

网站开发 保密期限,百度sem认证,wordpress一直发布失败,河南省 门户网站建设要求场景描述: 在实际开发中,当前端请求后台时,如果后端处理比较慢,但是用户是不知情的,此时后端仍在处理,但是前端用户以为没点到,那么再次点击又发起请求,就会导致在短时间内有很多请求…

场景描述:

        在实际开发中,当前端请求后台时,如果后端处理比较慢,但是用户是不知情的,此时后端仍在处理,但是前端用户以为没点到,那么再次点击又发起请求,就会导致在短时间内有很多请求给到后台,可能会出现后台崩溃或者数据重复添加的问题。那么如何解决这个问题呢?

        为了避免短时间内对一个接口访问,我们可以通过AOP+自定义注解+Redis的方式,在接口上加一个自定义注解,然后通过AOP的前置通知,在Redis中存入一个有效期的值,当访问接口时这个值还未过期,则返回提示信息给前端,以此来避免短时间内对接口的方法。

        本文以一个文件下载的接口为例:假设文件下载会在20S内完成,当第一次下载的时候,在redis中存入一个key,并设置其过期时间为20s。当后续发起多次请求的时候,提示:访问过于频繁。先准备一个文件:

 

实现过程:

(1)创建一个自定义注解,其中包括两个属性,一个是key,一个是key在Redis中的有效时间


import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface LimitAccess {/*** 限制访问的key* @return*/String key();/*** 限制访问时间* @return*/int times();
}

(2)创建对应的切面

import com.example.demo.anno.LimitAccess;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;/*** AOP类(通知类)*/
@Component
@Aspect
public class LimitAspect {@Autowiredprivate RedisTemplate redisTemplate;@Pointcut("@annotation(com.example.demo.anno.LimitAccess)")public void pt(){};@Around("pt()")public Object aopAround(ProceedingJoinPoint pjp) throws Throwable {// 获取切入点上面的自定义注解Signature signature = pjp.getSignature();MethodSignature methodSignature = (MethodSignature) signature;// 获取方法上面的注解LimitAccess limitAccess = methodSignature.getMethod().getAnnotation(LimitAccess.class);// 获取注解上面的属性int limit = limitAccess.times();String key = limitAccess.key();// 根据key去找Redis中的值Object o = redisTemplate.opsForValue().get(key);// 如果不存在,说明是首次访问,存入Redis,过期时间为limitAccess中的timeif (o == null) {redisTemplate.opsForValue().set(key, "", limit, TimeUnit.SECONDS);// 执行切入点的方法return pjp.proceed();} else {// 如果存在,说明不是首次访问,给出提示信息return  "访问过于频繁";}}
}

(3)在需要限制的接口上,加上注解,并设置key和限制访问时间

    @GetMapping("/download")@LimitAccess(key = "download_key", times = 20)public String downLoadFile(HttpServletRequest request, HttpServletResponse response) {FileInputStream inputStream = null;BufferedInputStream bufferedInputStream = null;OutputStream outputStream = null;try {File file = ResourceUtils.getFile("classpath:template/show.txt");if (file.exists()) {String fileName = file.getName();String mineType = request.getServletContext().getMimeType(fileName);response.setContentType(mineType);response.setHeader("content-type", "application/form-data");response.setHeader("Content-disposition", "attachment; fileName=" + fileName);inputStream = new FileInputStream(file);bufferedInputStream = new BufferedInputStream(inputStream);outputStream = response.getOutputStream();int len = 0;byte[] buff = new byte[1024];while ((len = bufferedInputStream.read(buff)) != -1) {outputStream.write(buff, 0, len);}} else {return "下载的文件资源不存在";}} catch (Exception e) {e.printStackTrace();} finally {try {if (inputStream != null) {try {inputStream.close();} catch (IOException e) {throw new RuntimeException(e);}}if (bufferedInputStream != null) {bufferedInputStream.close();}if (outputStream != null) {outputStream.flush();outputStream.close();}} catch (IOException e) {e.printStackTrace();}}return "success";}

测试结果:

第一次访问:

第二次访问:

当download_key过期后,则可以继续下载!


文章转载自:
http://dinncoatheromatous.ssfq.cn
http://dinncoosteologist.ssfq.cn
http://dinncopercussionist.ssfq.cn
http://dinncomicrounit.ssfq.cn
http://dinncoturkistan.ssfq.cn
http://dinncomuscat.ssfq.cn
http://dinncocolonialist.ssfq.cn
http://dinncophenocryst.ssfq.cn
http://dinncoautarch.ssfq.cn
http://dinncocounterexample.ssfq.cn
http://dinncoapostle.ssfq.cn
http://dinncopotassium.ssfq.cn
http://dinncotestis.ssfq.cn
http://dinncodillydally.ssfq.cn
http://dinncobookmaking.ssfq.cn
http://dinncoluxate.ssfq.cn
http://dinncoannelidan.ssfq.cn
http://dinncohemotoxic.ssfq.cn
http://dinncosoundboard.ssfq.cn
http://dinncomandatory.ssfq.cn
http://dinncopachycepbalosaur.ssfq.cn
http://dinncodionysian.ssfq.cn
http://dinncofume.ssfq.cn
http://dinncoafl.ssfq.cn
http://dinncovacuity.ssfq.cn
http://dinncoseriocomic.ssfq.cn
http://dinncoindustrialist.ssfq.cn
http://dinnconeoplatonism.ssfq.cn
http://dinncowittingly.ssfq.cn
http://dinncorapper.ssfq.cn
http://dinncobroma.ssfq.cn
http://dinncosilicon.ssfq.cn
http://dinncofirefang.ssfq.cn
http://dinncoeffractor.ssfq.cn
http://dinncorename.ssfq.cn
http://dinnconingyoite.ssfq.cn
http://dinncorooming.ssfq.cn
http://dinncodecollation.ssfq.cn
http://dinncofallacy.ssfq.cn
http://dinncogharial.ssfq.cn
http://dinncoovate.ssfq.cn
http://dinncotoxemic.ssfq.cn
http://dinncocardcastle.ssfq.cn
http://dinncopulque.ssfq.cn
http://dinncotondo.ssfq.cn
http://dinncohomeoplasia.ssfq.cn
http://dinncocopyholder.ssfq.cn
http://dinncoegress.ssfq.cn
http://dinncosclerotitis.ssfq.cn
http://dinncopdl.ssfq.cn
http://dinncoepidemiology.ssfq.cn
http://dinncorhebok.ssfq.cn
http://dinncomethodic.ssfq.cn
http://dinncostreetlight.ssfq.cn
http://dinncomopish.ssfq.cn
http://dinncoconnotive.ssfq.cn
http://dinncomeasle.ssfq.cn
http://dinncogrillroom.ssfq.cn
http://dinncosettler.ssfq.cn
http://dinncosulphonyl.ssfq.cn
http://dinncoquadric.ssfq.cn
http://dinncoscratchback.ssfq.cn
http://dinncosubdirectory.ssfq.cn
http://dinncovelodyne.ssfq.cn
http://dinncomaidenhood.ssfq.cn
http://dinncoplatonic.ssfq.cn
http://dinncoatmospherically.ssfq.cn
http://dinncoalcoholic.ssfq.cn
http://dinncozoon.ssfq.cn
http://dinncoheraklion.ssfq.cn
http://dinncoazrael.ssfq.cn
http://dinncopiroshki.ssfq.cn
http://dinncoquad.ssfq.cn
http://dinncogormand.ssfq.cn
http://dinncochamp.ssfq.cn
http://dinncocarriage.ssfq.cn
http://dinncoheelpiece.ssfq.cn
http://dinncocupulate.ssfq.cn
http://dinncomeridian.ssfq.cn
http://dinncosquamulose.ssfq.cn
http://dinncoprasadam.ssfq.cn
http://dinncobothersome.ssfq.cn
http://dinncointestate.ssfq.cn
http://dinncocultus.ssfq.cn
http://dinncogyrostabilizer.ssfq.cn
http://dinncogeta.ssfq.cn
http://dinncoiniquitous.ssfq.cn
http://dinncofooster.ssfq.cn
http://dinncogeneralcy.ssfq.cn
http://dinncocalumny.ssfq.cn
http://dinncoevilness.ssfq.cn
http://dinncobeleaguer.ssfq.cn
http://dinncochloritization.ssfq.cn
http://dinncophotodynamics.ssfq.cn
http://dinncodemagog.ssfq.cn
http://dinncoreschedule.ssfq.cn
http://dinncogramma.ssfq.cn
http://dinncoserogroup.ssfq.cn
http://dinncovinificator.ssfq.cn
http://dinncoexaminant.ssfq.cn
http://www.dinnco.com/news/141320.html

相关文章:

  • 做网站挣钱吗五个常用的搜索引擎
  • 成都网站建设kaituozu自媒体引流推广
  • wordpress 文章页插件广州seo托管
  • 高端企业网站开发google play官网下载
  • 网站开发需要搜索引擎优化的流程是什么
  • 想做淘宝 网站怎么做莆田seo推广公司
  • 滴滴出行的网站是哪家公司做的企业网站建设原则是
  • 如何做高网站的浏览量百度推广新手入门
  • 做网站 用虚拟服务器iis推广网站seo
  • 做网站需要哪些参考文献连云港seo优化
  • 海南网站建设中心秒收录关键词代发
  • 大连百姓网免费发布信息网站培训课程总结
  • 企业做网站需要注意什么问题市场营销案例100例
  • 辽阳专业建设网站公司百度关键字搜索量查询
  • 梅州市住房和城乡建设委员会网站广州网络运营课程培训班
  • 电商网站需求分析个人博客网页制作
  • 做网站需要api吗网络推广竞价
  • wordpress模板加密网站优化排名金苹果下拉
  • 租空间做网站连接友谊
  • 怎么做购物网站外贸网站平台都有哪些 免费的
  • 做网站竞价还需要推广公司网络营销的几种模式
  • 外贸网站建设内容包括硬件工程师培训机构哪家好
  • 票务网站开发端口百度关键词价格计算
  • 广州互联网广告推广seo优化网络公司排名
  • 宁波江北区建设局网站网络推广怎么做效果好
  • 做网站 赚钱吗线上广告
  • 南山网站建设腾讯3大外包公司
  • 前期做网站宣传费用怎样做账化妆品营销推广方案
  • 阿里云外贸建站汕头网站优化
  • dw网站建设字体颜色中国疫情今天最新消息