「Spring Boot」HandlerInterceptorインタフェースを実装するサンプル

Javaコード

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // ログインチェック処理
        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 {

    }
}

dispatcher.xml

<mvc:interceptors>
<mvc:mapping path="/**" />
<bean class="com.arkgame.study.LoginInterceptor">
//some code
</bean>

Software

Posted by arkgame