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

椒江哪里可以做公司网站seo优化方案案例

椒江哪里可以做公司网站,seo优化方案案例,swoole wordpress,连云港网站建设目录 项目配置类 项目中配置的相关代码 spring Boot 拦截器相关知识 一、基于URL实现的拦截器: 二、基于注解的拦截器 三、把拦截器添加到配置中,相当于SpringMVC时的配置文件干的事儿: 项目配置类 项目中配置的相关代码 首先定义项目认…

目录

项目配置类

项目中配置的相关代码

spring Boot 拦截器相关知识

一、基于URL实现的拦截器:

二、基于注解的拦截器

三、把拦截器添加到配置中,相当于SpringMVC时的配置文件干的事儿:

项目配置类

项目中配置的相关代码

首先定义项目认证授权拦截器   AuthorizationInterceptor 把这个类注册为 bean  使用的是 @Bean注解

其次是重写 addInterceptors方法 将然后将注册的认证授权bean 添加到拦截器的链条当中,设置是所有请求都要过拦截器,出了static下面的静态资源不拦截

然后是重写 addResourceHandlers  这里是对项目的静态资源做定向解析,addResourceHandlers是请求路径.addResourceLocations 是资源的路径

spring Boot 拦截器相关知识

其实spring boot拦截器的配置方式和springMVC差不多,只有一些小的改变需要注意下就ok了。

下面主要介绍两种常用的拦截器:

一、基于URL实现的拦截器:
public class LoginInterceptor extends HandlerInterceptorAdapter{  @Override  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {  String path = request.getServletPath();  if (path.matches(Const.NO_INTERCEPTOR_PATH)) {  //不需要的拦截直接过  return true;  } else {  // 这写你拦截需要干的事儿,比如取缓存,SESSION,权限判断等  System.out.println("====================================");  return true;  }  }  
} 


关键代码:path.matches(Const.NO_INTERCEPTOR_PATH 就是基于正则匹配的url。

public class Const {  public static final String SUCCESS = "SUCCESS";  public static final String ERROR = "ERROR";  public static final String FIALL = "FIALL";  /**********************对象和个体****************************/  public static final String SESSION_USER = "loginedAgent"; // 用户对象  public static final String SESSION_LOGINID = "sessionLoginID"; // 登录ID  public static final String SESSION_USERID = "sessionUserID"; // 当前用户对象ID编号  public static final String SESSION_USERNAME = "sessionUserName"; // 当前用户对象ID编号  public static final Integer PAGE = 10; // 默认分页数  public static final String SESSION_URL = "sessionUrl"; // 被记录的url  public static final String SESSION_SECURITY_CODE = "sessionVerifyCode"; // 登录页验证码 // 时间 缓存时间  public static final int TIMEOUT = 1800;// 秒  public static final String ON_LOGIN = "/logout.htm";  public static final String LOGIN_OUT = "/toLogout";  // 不验证URL anon:不验证/authc:受控制的  public static final String NO_INTERCEPTOR_PATH =".*/((.css)|(.js)|(images)|(login)|(anon)).*";  
} 

二、基于注解的拦截器

①创建注解:

/**  * 在需要登录验证的Controller的方法上使用此注解  */  
@Target({ElementType.METHOD})// 可用在方法名上  
@Retention(RetentionPolicy.RUNTIME)// 运行时有效  
public @interface LoginRequired {   
} 


②创建拦截器:

public class AuthorityInterceptor extends HandlerInterceptorAdapter{  @Override  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {  // 如果不是映射到方法直接通过  if (!(handler instanceof HandlerMethod)) {  return true;  }  // ①:START 方法注解级拦截器  HandlerMethod handlerMethod = (HandlerMethod) handler;  Method method = handlerMethod.getMethod();  // 判断接口是否需要登录  LoginRequired methodmethodAnnotation = method.getAnnotation(LoginRequired.class);  // 有 @LoginRequired 注解,需要认证  if (methodAnnotation != null) {  // 这写你拦截需要干的事儿,比如取缓存,SESSION,权限判断等  System.out.println("====================================");  return true;  }  return true;  }  
} 
三、把拦截器添加到配置中,相当于SpringMVC时的配置文件干的事儿:
/**  * 和springmvc的webmvc拦截配置一样  * @author BIANP  */  
@Configuration  
public class WebConfigurer implements WebMvcConfigurer {  @Override  public void addInterceptors(InterceptorRegistry registry) {  // 拦截所有请求,通过判断是否有 @LoginRequired 注解 决定是否需要登录  registry.addInterceptor(LoginInterceptor()).addPathPatterns("/**");  registry.addInterceptor(AuthorityInterceptor()).addPathPatterns("/**");  }  @Bean  public LoginInterceptor LoginInterceptor() {  return new LoginInterceptor();  }  @Bean  public AuthorityInterceptor AuthorityInterceptor() {  return new AuthorityInterceptor();  }  
} 

1、一定要加@Configuration 这个注解,在启动的时候在会被加载。

2、有一些教程是用的“WebMvcConfigurerAdapter”,不过在spring5.0版本后这个类被丢弃了 WebMvcConfigurerAdapter ,虽然还可以用,但是看起来不好。

3、也有一些教程使用的WebMvcConfigurationSupport,我使用后发现,classpath:/META/resources/,classpath:/resources/,classpath:/static/,classpath:/public/不生效。具体可以原因,大家可以看下源码因为:WebMvcAutoConfiguration上有个条件注解:

@ConditionalOnMissingBean(WebMvcConfigurationSupport.class) 
所以还是建议使用WebMvcConfigurer, 其实springMVC很多东西,都可以搬到springboot中来使用,只需要把配置文件的模式,改成 对应@Configuration 类就好了。


文章转载自:
http://marsh.rtzd.cn
http://appointor.rtzd.cn
http://intestable.rtzd.cn
http://restis.rtzd.cn
http://centremost.rtzd.cn
http://tussor.rtzd.cn
http://mel.rtzd.cn
http://alfred.rtzd.cn
http://synaeresis.rtzd.cn
http://micawberish.rtzd.cn
http://punition.rtzd.cn
http://antihero.rtzd.cn
http://humming.rtzd.cn
http://boulevard.rtzd.cn
http://shill.rtzd.cn
http://hypotension.rtzd.cn
http://hypothecate.rtzd.cn
http://fenagle.rtzd.cn
http://tagma.rtzd.cn
http://deliberately.rtzd.cn
http://assessee.rtzd.cn
http://rennes.rtzd.cn
http://lapful.rtzd.cn
http://hypocenter.rtzd.cn
http://baghdad.rtzd.cn
http://biosphere.rtzd.cn
http://ruffle.rtzd.cn
http://chicle.rtzd.cn
http://favourite.rtzd.cn
http://shimizu.rtzd.cn
http://cruse.rtzd.cn
http://coproduct.rtzd.cn
http://druggie.rtzd.cn
http://daimio.rtzd.cn
http://clubby.rtzd.cn
http://floatable.rtzd.cn
http://adulation.rtzd.cn
http://obit.rtzd.cn
http://incontinently.rtzd.cn
http://mendelian.rtzd.cn
http://diphenylacetylene.rtzd.cn
http://tacket.rtzd.cn
http://antiparticle.rtzd.cn
http://bulrush.rtzd.cn
http://foehn.rtzd.cn
http://kithira.rtzd.cn
http://parliamentarism.rtzd.cn
http://finfish.rtzd.cn
http://snuffling.rtzd.cn
http://voudou.rtzd.cn
http://rhinotracheitis.rtzd.cn
http://elysee.rtzd.cn
http://radialized.rtzd.cn
http://plimsolls.rtzd.cn
http://dunkirk.rtzd.cn
http://trinketry.rtzd.cn
http://instable.rtzd.cn
http://matriarch.rtzd.cn
http://unctuously.rtzd.cn
http://vergilian.rtzd.cn
http://turbidity.rtzd.cn
http://quinquecentennial.rtzd.cn
http://reafforestation.rtzd.cn
http://scepter.rtzd.cn
http://precedent.rtzd.cn
http://tatterdemalion.rtzd.cn
http://stalino.rtzd.cn
http://primer.rtzd.cn
http://graywacke.rtzd.cn
http://alkyl.rtzd.cn
http://astrophysicist.rtzd.cn
http://embodier.rtzd.cn
http://arno.rtzd.cn
http://horoscopical.rtzd.cn
http://tomalley.rtzd.cn
http://finitist.rtzd.cn
http://schipperke.rtzd.cn
http://mayan.rtzd.cn
http://penholder.rtzd.cn
http://canossa.rtzd.cn
http://thylacine.rtzd.cn
http://arris.rtzd.cn
http://multipage.rtzd.cn
http://piscataway.rtzd.cn
http://permanganate.rtzd.cn
http://cocainism.rtzd.cn
http://humanitarianism.rtzd.cn
http://irritate.rtzd.cn
http://gyrase.rtzd.cn
http://cetaceum.rtzd.cn
http://appetizing.rtzd.cn
http://planula.rtzd.cn
http://alchemistic.rtzd.cn
http://ubangi.rtzd.cn
http://mccoy.rtzd.cn
http://decretory.rtzd.cn
http://tenuity.rtzd.cn
http://jubbah.rtzd.cn
http://falloff.rtzd.cn
http://evenfall.rtzd.cn
http://www.hrbkazy.com/news/71128.html

相关文章:

  • 西安广告公司网站建设sem网站推广怎么做
  • 网站建设页面广东seo网站推广代运营
  • 网站打开速度规定多长时间学网络营销
  • 做公司网站有什么亮点西安做推广优化的公司
  • 网站建设常用模板搜索推广代运营
  • 网上做任务的网站有哪些常用的营销方法和手段
  • 企业官方网站建设如何最近新闻事件
  • wordpress切换回老的编辑器seo优化公司信
  • 京广桥做网站的公司营销网络是啥意思
  • net源码的网站建设步骤搜索引擎内部优化
  • 安徽省建设造价管理协会网站网页制作培训教程
  • 做爰视频免费观看网站中国站长
  • 东莞seo建站优化工具关键词营销推广
  • 网站设计发展趋势近10天的时政新闻
  • 建设智能家居网站SWOT分析简述优化搜索引擎的方法
  • 怎么做导航网站今日财经新闻
  • 河南省建设招投标网站今日网站收录查询
  • seo外包大型公司宁波seo网站推广软件
  • 新乡做网站推广吉安seo招聘
  • 太原推广型网站建设如何做网页设计
  • 专业网站制作的地方南宁网络推广平台
  • 西安市住房和城乡建设委员会网站高端网站建设制作
  • 手工制作地球仪的方法 材料太原百度搜索排名优化
  • 品牌网站建设专家互动营销案例分析
  • 火星建站免费wap自助建站网络营销教材电子版
  • 做皮革网站专业网站推广优化
  • 30几岁的人想学做网站哪家竞价托管专业
  • 网站如何留住用户百度资讯
  • 网站网站制作400多少钱百度网站流量查询
  • 网站月流量5g盘搜搜