All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.bestwu.logging.HandlerMethodHandlerInterceptor.kt Maven / Gradle / Ivy

There is a newer version: 2.0.11
Show newest version
package cn.bestwu.logging

import cn.bestwu.logging.annotation.NoRequestLogging
import org.springframework.boot.web.servlet.error.ErrorController
import org.springframework.web.method.HandlerMethod
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

/**
 * 保存 HandlerMethod
 *
 * @author Peter Wu
 */
class HandlerMethodHandlerInterceptor : HandlerInterceptorAdapter() {

    companion object {
        val HANDLER_METHOD = HandlerMethodHandlerInterceptor::class.java.name + ".HandlerMethod"
    }

    override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
        if (handler is HandlerMethod && !handler.beanType.isAnnotationPresent(NoRequestLogging::class.java) && !handler.hasMethodAnnotation(NoRequestLogging::class.java) && handler.bean !is ErrorController)
            request.setAttribute(HANDLER_METHOD, handler)
        return super.preHandle(request, response, handler)
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy