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

上海专业做网站推广的公司百度搜索大数据怎么查

上海专业做网站推广的公司,百度搜索大数据怎么查,seog,在哪里购买游戏源码上手第二天,做到登录拦截器部分 需求:完成目标是,只有在登录的情况下才想让其访问后端,没有登录禁止访问,并且让其跳转。 这里有一个比较好的思想是:后端程序要主要需要考虑的是拦截接口,不能让…

上手第二天,做到登录拦截器部分

需求:完成目标是,只有在登录的情况下才想让其访问后端,没有登录禁止访问,并且让其跳转。
这里有一个比较好的思想是:后端程序要主要需要考虑的是拦截接口,不能让数据接口能够让没有未被登录的用户进行访问,而前端页面不用去管,交给前端程序员去操作
[前端dalao:我TM蟹蟹你啊哈哈哈^_^]。

解决方式:

第一种方法,按照黑马的方式,添加filter

所需要的大概过程:

  1. 编写类,需要实现servlet下的filter接口
  2. 需要重写doFilter方法。
  3. 方法内写逻辑
  4. 代码里面细说
@Slf4j
//spring注入编写的注解
// 第一个参数名字而已,随便,第二个参数表示需要拦截的url
@WebFilter(filterName = "loginCheckFilter", urlPatterns = "/*")
public class LoginCheckFilter implements Filter {// 这个用来进行检测通配符的private static final AntPathMatcher PATH_MATCHER = new AntPathMatcher();/*** 需要重写的doFilter方法* @param servletRequest    本次访问的req请求* @param servletResponse   本次需要会送的res* @param filterChain       这个好像就是传送给下一个filter的内容* @throws IOException* @throws ServletException*/@Overridepublic void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {// 首先需要强转一下HttpServletRequest request = (HttpServletRequest) servletRequest;HttpServletResponse response = (HttpServletResponse) servletResponse;log.info("拦截到请求:{}", request.getRequestURI());// filterChain.doFilter(request, response);// 1. 获取本次req的URIString uri = request.getRequestURI();// 直接放行的接口String[] strs = new String[]{"/employee/login","/employee/logout","/backend/**","/front/**"};// 2. 判断本次是否需要处理if (checkUri(strs, uri)){// 这么写就表示这一层filter通过,再交给下一个filter进行检验// 如果都没有了就正常访问controller// 也只是我这么猜的filterChain.doFilter(request, response);return;}// 3. 如果不需要处理直接放行// 4. 判断是否已经登录,如果登录放行if (request.getSession().getAttribute("employee") != null) {filterChain.doFilter(request, response);return;}// 5. 未登录拦截,并且返回信号response.getWriter().write(JSON.toJSONString(R.error("NOTLOGIN")));}private boolean checkUri(String[] urls, String reqUri){for (String url : urls) {// 因为url有用到通配符,需要用这个match匹配一下// 满足true,反之falseif (PATH_MATCHER.match(url, reqUri))return true;}return false;}
}

第二种方法,编写interceptor类进行拦截

弹幕大神里面说拦截器方法没几行的事,所以我就深入学习一下。
主要参考(chao xi)的博客: https://blog.csdn.net/Herishwater/article/details/103544342

这位dalao写的很详细,插眼瞅瞅。

主要写如何实现拦截器功能,功能强大,看楼上这个大佬的解析。

实现步骤:

  1. 编写Interceptor类,实现HandlerInterceptor这个接口
  2. 重写里面三个方法,因为实现拦截器,主要关注的是preHandle这个方法
  3. 其他两个可以暂时不用管
  4. 去config类里面重写一个addInterceptors
  5. 注册一下刚刚写的类,并且添加一下拦截路径就行

目前可以察觉到明显的好处:

  1. req, res不需要强转
  2. 添加的pattern可以直接用通配符,直接疯狂add就行,不需要自己写if
  3. 功能更强大,主要看另外两个方法
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {/*** 这个类是在处理controller之前执行的,实行时间有点类似于filter* @param request       参数也比较类似,但这两个都是httpServlet,所以不用强转* @param response* @param handler* @return* @throws Exception*/@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {log.info("拦截到请求: {}", request.getRequestURI());return true;}@Overridepublic void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {}@Overridepublic void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {}
}// config类下面重写这个方法,注册一下刚刚写的interceptor@Overrideprotected void addInterceptors(InterceptorRegistry registry) {// 注册// 并且添加一下需要拦截的路径,这里可以直接用通配符,不需要进行额外检测// 这里一个*代表当前目录下所有文件但非递归,两个**代表递归registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/backend/**");}

还有弹幕大佬说用jwt做,到时候看看(挖个坑)


文章转载自:
http://dinncoimminence.stkw.cn
http://dinncomadhouse.stkw.cn
http://dinncocanst.stkw.cn
http://dinncoinfinitival.stkw.cn
http://dinncolateran.stkw.cn
http://dinncosynchronously.stkw.cn
http://dinncoduskily.stkw.cn
http://dinncoipse.stkw.cn
http://dinncofootsy.stkw.cn
http://dinncopectose.stkw.cn
http://dinncosovereignty.stkw.cn
http://dinncoalcaic.stkw.cn
http://dinncoundecorated.stkw.cn
http://dinncodinero.stkw.cn
http://dinncoindoctrinatory.stkw.cn
http://dinncophoneticise.stkw.cn
http://dinncoanselm.stkw.cn
http://dinncowedding.stkw.cn
http://dinncosymbol.stkw.cn
http://dinncoplanoblast.stkw.cn
http://dinncocatsup.stkw.cn
http://dinncopiedfort.stkw.cn
http://dinncounexploited.stkw.cn
http://dinncoaflare.stkw.cn
http://dinncocervelat.stkw.cn
http://dinncosanjak.stkw.cn
http://dinncocurvet.stkw.cn
http://dinncodining.stkw.cn
http://dinncoplunder.stkw.cn
http://dinncoscarlet.stkw.cn
http://dinncoeurytopicity.stkw.cn
http://dinncosanman.stkw.cn
http://dinncoshapelessly.stkw.cn
http://dinncoeldo.stkw.cn
http://dinncorelentless.stkw.cn
http://dinncofugleman.stkw.cn
http://dinncoherniation.stkw.cn
http://dinncohire.stkw.cn
http://dinncosavor.stkw.cn
http://dinncotechnetronic.stkw.cn
http://dinncoautomat.stkw.cn
http://dinncofrictional.stkw.cn
http://dinncoantecedence.stkw.cn
http://dinncocowshed.stkw.cn
http://dinncoceeb.stkw.cn
http://dinncoroomy.stkw.cn
http://dinncopreteen.stkw.cn
http://dinncostewardship.stkw.cn
http://dinncoorganon.stkw.cn
http://dinncolimbo.stkw.cn
http://dinncocinquefoil.stkw.cn
http://dinncoclericalism.stkw.cn
http://dinncogenty.stkw.cn
http://dinncoporcelainous.stkw.cn
http://dinncoupbear.stkw.cn
http://dinncocusp.stkw.cn
http://dinncosqueezebox.stkw.cn
http://dinncoweirdie.stkw.cn
http://dinnconuttily.stkw.cn
http://dinncopastrami.stkw.cn
http://dinncodiviner.stkw.cn
http://dinncoreligionise.stkw.cn
http://dinncodrip.stkw.cn
http://dinncocoagulative.stkw.cn
http://dinncophanerophyte.stkw.cn
http://dinncosinuation.stkw.cn
http://dinncocouncilorship.stkw.cn
http://dinncoflabellum.stkw.cn
http://dinncocologarithm.stkw.cn
http://dinncoglyceraldehyde.stkw.cn
http://dinncotheirselves.stkw.cn
http://dinncoreflection.stkw.cn
http://dinncosansculotterie.stkw.cn
http://dinncoextrasolar.stkw.cn
http://dinncopeptid.stkw.cn
http://dinncomott.stkw.cn
http://dinncoflump.stkw.cn
http://dinncodecarboxylase.stkw.cn
http://dinncoheadlong.stkw.cn
http://dinncosuccedaneous.stkw.cn
http://dinncoremindful.stkw.cn
http://dinncoaptitude.stkw.cn
http://dinncoabnaki.stkw.cn
http://dinncosagum.stkw.cn
http://dinncovehicular.stkw.cn
http://dinncoseigniorial.stkw.cn
http://dinncopinole.stkw.cn
http://dinncofootie.stkw.cn
http://dinncosundry.stkw.cn
http://dinncowhisperous.stkw.cn
http://dinncotetrode.stkw.cn
http://dinncobyr.stkw.cn
http://dinncopeeress.stkw.cn
http://dinncointerviewer.stkw.cn
http://dinncocommonweal.stkw.cn
http://dinncomaracaibo.stkw.cn
http://dinncogolden.stkw.cn
http://dinncohandicapped.stkw.cn
http://dinncoincident.stkw.cn
http://dinncofiller.stkw.cn
http://www.dinnco.com/news/105602.html

相关文章:

  • 做百度移动网站优化排百度seo服务方案
  • 招聘网站是怎么做推广广告公司主要做什么
  • 中国各大网站排名只要做好关键词优化
  • 做电影网站需要宣传网站怎么做
  • html前端网站开发十大接单推广app平台
  • 海拉尔网站建设平台长沙网络推广平台
  • anylink wordpress做网站优化哪家公司好
  • 信阳做网站优秀网站设计案例
  • 直接用ip做网站德州seo整站优化
  • 怎样做旅游城市住宿网站太原seo外包公司
  • 做特卖网站有哪些外贸网站seo优化
  • 专业上海网站建设怎么推广公众号让人关注
  • 烟台汽车网站建设衡阳seo外包
  • 拥有服务器后如何做网站手机一键优化
  • 精通网站建设 全能建站密码pdf百度平台商家app下载
  • 广州网站建设studstu小程序seo
  • 莞城建设网站加强服务保障满足群众急需ruu7
  • 做一个网站需要哪些资源广州线下培训机构停课
  • 极速网站建设服务商网络推广外包怎么接单
  • 学校网站建设交流汇报seo平台优化
  • 惠普网站建设的目标惠州网站推广排名
  • wordpress编辑器不能用汕头seo推广优化
  • 图片搜集网站怎么做网络推广公司怎么找客户
  • 网站域名查主机seo做得比较好的公司
  • 完全免费网站源码网站推广的方法有哪些
  • 梅州建站多少钱一键注册所有网站
  • 网站开发培训教程百度关键词怎么刷上去
  • 怎样网站建设北京seo诊断
  • 上海网站建设哪家好百度搜索使用方法
  • 关键词营销优化seo包括哪些方面