springboot 详解 (五)interceptor

本文介绍了一个具体的 Spring Boot 拦截器实现案例,该案例详细展示了如何使用 Spring Boot 实现登录验证的拦截器,并配置其路径规则及资源处理方式。

 

 ----------------------------------------------------------------------------------------------------------------

springboot 详解 (一) helloworld                                    下载demo          

springboot 详解 (二) crud                                             下载demo     

springboot 详解 (三) 多数据源                                        下载demo      

springboot 详解 (四)redis & filter                                    下载demo    

springboot 详解 (五)interceptor                                       下载demo     

springboot 详解 (六)servlet & scheduled & listener         下载demo     

springboot 详解(七) dubbox & zookeeper   下载(productor) 下载(constumser)

springboot 同步解耦 异步化 下载demo

springboot jenkins docker 部署 

springboot 详解(八) springboot & springcloud 

----------------------------------------------------------------------------------------------------------------

 

 

 

package com.curiousby.cn.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.curiousby.cn.constants.Constants;
import com.curiousby.cn.one.entity.User;


public class LoginAuthInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
                             Object handler)
            throws Exception {  
        User user = (User)request.getSession().getAttribute(Constants.USER);
        if (null == user) {
            response.sendRedirect("/SpringBootWebDemo/web/static/forward");
            return false;
        }
        return true;
    }

    @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 { 
        
    }

  

}

 

 

 

package com.curiousby.cn.configurer;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.curiousby.cn.interceptor.LoginAuthInterceptor;


@Configuration
public class WebAppConfigurer extends WebMvcConfigurerAdapter {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginAuthInterceptor()).addPathPatterns("/web/**").excludePathPatterns("/web/static/**"); 
        super.addInterceptors(registry);
    }
    
    
    
    //优先级 :META-INFO/resources > resources > static > public 
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/img/**").addResourceLocations("classpath:/img/");
        super.addResourceHandlers(registry);
    }
}

 

 

访问 http://localhost:8080/SpringBootWebDemo/web/users/7

 会自动重定向到

http://localhost:8080/SpringBootWebDemo/web/static/forword

 

拦截器中添加了SpringBootWebDemo 这是我的工程名

server.context-path=/SpringBootWebDemo

 

也许默认更好点

 

 

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。



 
 
 谢谢您的赞助,我会做的更好!

 

 

 

 

 

 

内容概要:本文研究基于SPEA2(Strength Pareto Evolutionary Algorithm 2)的移动机器人路径规划方法,利用该多目标优化算法在复杂环境中寻找最优或近似最优的机器人运动路径。文中详细阐述了SPEA2算法的基本原理及其在路径规划中的具体应用流程,并通过Matlab代码实现仿真验证,展示了算法在避障、路径平滑性和多目标优化方面的有效性。研究结合栅格地图建模,定义了包括路径长度、安全性与能耗在内的多个优化目标,体现了SPEA2在处理多目标冲突问题上的优势。; 适合人群:具备一定Matlab编程基础,从事智能优化算法、机器人路径规划或人工智能相关领域的研究生及科研人员;熟悉进化算法并希望将其应用于实际工程问题的技术开发者。; 使用场景及目标:①掌握SPEA2算法在移动机器人路径规划中的建模与实现方法;②学习如何将多目标优化思想融【移动机器人路径规划】基于SPEA2的移动机器人路径规划研究(Matlab代码实现)入路径规划问题;③为后续研究NSGA-II、MOEA/D等其他多目标算法提供对比基准和技术参考; 阅读建议:此资源以Matlab代码为核心支撑,建议读者结合算法原理部分仔细研读代码实现细节,动手运行仿真案例,深入理解适应度函数设计、非支配解集维护及环境建模的关键步骤,从而全面提升对多目标进化算法在机器人应用中的实践能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值