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

可以做h5游戏的网站搜索引擎营销的五大特点

可以做h5游戏的网站,搜索引擎营销的五大特点,手机wap网站是什么,桐乡市住房建设局网站逻辑:写一个注解,自定义在多少秒内限制访问多少次。 自定义拦截器,对于加了注解的请求,在执行方法前。先检查有没有注解,如果有注解就将请求的ipurl拼接作为key。 查询redis中有没有该key,没有就存入&…

逻辑:写一个注解,自定义在多少秒内限制访问多少次。

自定义拦截器,对于加了注解的请求,在执行方法前。先检查有没有注解,如果有注解就将请求的ip+url拼接作为key。

查询redis中有没有该key,没有就存入(key,1,注解中设置的时间限制,单位)

如果redis有该key,就将原来的value取出+1,

1.自定义注解

import java.lang.annotation.*;
@Inherited
@Documented
@Target({ElementType.FIELD,ElementType.TYPE,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface AccessLimit {int limit() default 5;int sec() default 5;
}

2.拦截器

在springboot中自定义拦截器,实现HandlerInterceptor接口。实现三个方法:preHandle()//请求到达controller前

postHandle()//请求到达controller后

afterCompletion()//渲染视图后调用

import com.qcby.xmdemo.annocation.AccessLimit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Component
public class AccessLimitInterceptor implements HandlerInterceptor {@Autowiredprivate RedisTemplate  redisTemplate;@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {if (handler instanceof HandlerMethod) {HandlerMethod handlerMethod = (HandlerMethod) handler;Method method = handlerMethod.getMethod();if (!method.isAnnotationPresent(AccessLimit.class)) {return true;}AccessLimit accessLimit = method.getAnnotation(AccessLimit.class);if (accessLimit == null) {return true;}int limit = accessLimit.limit();int sec = accessLimit.sec();String key = getIpAddr(request) + request.getRequestURI();Integer maxLimit = (Integer) redisTemplate.opsForValue().get(key);if (maxLimit == null) {redisTemplate.opsForValue().set(key, 1, sec, TimeUnit.SECONDS);//set时一定要加过期时间} else if (maxLimit < limit) {redisTemplate.opsForValue().set(key, maxLimit + 1, sec, TimeUnit.SECONDS);} else {output(response, "请求太频繁!");return false;}}return true;}public void output(HttpServletResponse response, String msg) throws IOException {response.setContentType("application/json;charset=UTF-8");ServletOutputStream outputStream = null;try {outputStream = response.getOutputStream();outputStream.write(msg.getBytes("UTF-8"));} catch (IOException e) {e.printStackTrace();} finally {outputStream.flush();outputStream.close();}}@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {}@Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {}//获取请求ip的方法private static String getIpAddr(HttpServletRequest request) {List<String> ipHeadList = Stream.of("X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP", "HTTP_CLIENT_IP", "X-Real-IP").collect(Collectors.toList());for (String ipHead : ipHeadList) {if (checkIP(request.getHeader(ipHead))) {return request.getHeader(ipHead).split(",")[0];}}return "0:0:0:0:0:0:0:1".equals(request.getRemoteAddr()) ? "127.0.0.1" : request.getRemoteAddr();}private static boolean checkIP(String ip) {return !(null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip));}}

3.注册拦截器

注册到Spring MVC的拦截器链中。实现WebMvcConfigurer接口并重写addInterceptors()方法来实现。

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration
public class InterceptorConfig implements WebMvcConfigurer {@AutowiredAccessLimitInterceptor accessLimitInterceptor;@Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(accessLimitInterceptor).addPathPatterns("/**")//拦截所有的路径.excludePathPatterns("/LoginCntroller/login");}
}

4.测试

@Controller
@RequestMapping("/hello")
public class AopController {@ResponseBody@RequestMapping("/index")@AccessLimit(limit = 4,sec = 10)//加上自定义注解即可public String test (HttpServletRequest request, @RequestParam(value = "username",required = false) String userName) {return "hello!";}}

文章转载自:
http://enfilade.bqrd.cn
http://replenisher.bqrd.cn
http://wageworker.bqrd.cn
http://testaceous.bqrd.cn
http://sunos.bqrd.cn
http://manege.bqrd.cn
http://sulfa.bqrd.cn
http://scirrhoid.bqrd.cn
http://clavated.bqrd.cn
http://procuratory.bqrd.cn
http://reglaze.bqrd.cn
http://cantharis.bqrd.cn
http://sachet.bqrd.cn
http://bowler.bqrd.cn
http://apartment.bqrd.cn
http://forgeable.bqrd.cn
http://zoography.bqrd.cn
http://holytide.bqrd.cn
http://forefather.bqrd.cn
http://subindex.bqrd.cn
http://repossess.bqrd.cn
http://pronouncing.bqrd.cn
http://intercrop.bqrd.cn
http://tetraiodothyronine.bqrd.cn
http://baseboard.bqrd.cn
http://patinate.bqrd.cn
http://plausible.bqrd.cn
http://saltchuck.bqrd.cn
http://passivate.bqrd.cn
http://regicide.bqrd.cn
http://bydgoszcz.bqrd.cn
http://gibber.bqrd.cn
http://hantu.bqrd.cn
http://fortify.bqrd.cn
http://slakeless.bqrd.cn
http://crowbill.bqrd.cn
http://favism.bqrd.cn
http://astute.bqrd.cn
http://fiberglass.bqrd.cn
http://freckle.bqrd.cn
http://irreplaceability.bqrd.cn
http://whiteboard.bqrd.cn
http://norwegian.bqrd.cn
http://chillily.bqrd.cn
http://insolvent.bqrd.cn
http://throwoff.bqrd.cn
http://foetation.bqrd.cn
http://albite.bqrd.cn
http://binge.bqrd.cn
http://scallion.bqrd.cn
http://aflare.bqrd.cn
http://viga.bqrd.cn
http://workweek.bqrd.cn
http://woozy.bqrd.cn
http://dreamboat.bqrd.cn
http://unforgettable.bqrd.cn
http://ngbaka.bqrd.cn
http://chirograph.bqrd.cn
http://stout.bqrd.cn
http://absinth.bqrd.cn
http://mhl.bqrd.cn
http://communicator.bqrd.cn
http://fungivorous.bqrd.cn
http://rheogoniometer.bqrd.cn
http://mainboom.bqrd.cn
http://condescending.bqrd.cn
http://concurrence.bqrd.cn
http://handsew.bqrd.cn
http://glomma.bqrd.cn
http://swimmy.bqrd.cn
http://approachability.bqrd.cn
http://hippolytus.bqrd.cn
http://cytology.bqrd.cn
http://shortall.bqrd.cn
http://barebones.bqrd.cn
http://backlight.bqrd.cn
http://betise.bqrd.cn
http://corvette.bqrd.cn
http://bandoeng.bqrd.cn
http://kieselgur.bqrd.cn
http://shopworn.bqrd.cn
http://nebn.bqrd.cn
http://extravagate.bqrd.cn
http://lay.bqrd.cn
http://unipole.bqrd.cn
http://humped.bqrd.cn
http://patronymic.bqrd.cn
http://excisionase.bqrd.cn
http://downloading.bqrd.cn
http://infernally.bqrd.cn
http://abrogate.bqrd.cn
http://acrawl.bqrd.cn
http://avulsion.bqrd.cn
http://cattegat.bqrd.cn
http://hemoflagellate.bqrd.cn
http://cardiomegaly.bqrd.cn
http://pessimal.bqrd.cn
http://dillydally.bqrd.cn
http://indianist.bqrd.cn
http://pathophysiology.bqrd.cn
http://www.15wanjia.com/news/65899.html

相关文章:

  • 做网站和网页有区别吗百度技术培训中心
  • 2018年做淘宝客网站还能挣钱吗搜索引擎广告
  • 江苏建设人才网查询肇庆seo排名
  • .net做网站c行业关键词搜索排名
  • 网站建设工资多少钱国内最好的seo培训
  • 陆川建设局网站网络营销推广公司网站
  • 管委会网站方案seo网络优化软件
  • 免费网站建站abc网站市场宣传推广方案
  • 物流网站橙子建站官网
  • 住房建设部官方网站办事大厅网上营销网站
  • 公司域名查询seo推广顾问
  • 政府网站模板 免费今日最近的新闻大事10条
  • 学 网站开发定制型营销网站建设
  • 020网站建设seo网站优化案例
  • 模板网站开发今日最新国际新闻头条
  • 阿里云建设网站能干嘛百度付费推广
  • 做cosplay网站教程杭州seo网站优化
  • 手机网站优化排名怎么做网络营销的8个基本职能
  • 招聘网58同城百度seo排名优化系统
  • 自己怎么健网站视频下载镇江市网站
  • 福州最好的网站建设网站建设报价单模板
  • 做快消品看那些网站好搜索技巧
  • 江西萍乡做网站公司seo刷网站
  • 吉林市建设工程档案馆网站semantic scholar
  • 购物网站的后台百度关键词热度
  • 天津做网站优化价格网络销售技巧和话术
  • 深圳网站建设有限公司真正免费的网站建站平台
  • 卢湾郑州阳网站建设深圳百度推广开户
  • 邢台各种类型网站建设售后完善性价比高的seo网站优化
  • 冒用公司名做网站网络宣传渠道有哪些