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

com.hxl.miniapi.core.RequestMappingHandlerMapping.kt Maven / Gradle / Ivy

There is a newer version: 1.3.3
Show newest version
package com.hxl.miniapi.core

import com.hxl.miniapi.http.HttpRequestAdapter
import com.hxl.miniapi.utils.AntPathMatcher

class RequestMappingHandlerMapping(private val context: Context) {
    private val mappings = mutableListOf()
    private  val pathMatcher =AntPathMatcher()

    /**
    * @description: 注册一个mapping
    * @date: 2022/10/1 下午12:47
    */
    fun registerMapping(mappingInfo: MappingInfo){
        mappings.add(mappingInfo)
    }
    fun getHandler(httpRequestAdapter: HttpRequestAdapter): HandlerMapping?{
        val mappingInfo = mappings.find {
            pathMatcher.match(it.urlPatterns, httpRequestAdapter.getRequestPath()) && httpRequestAdapter.getRequestMethod()==it.httpMethod
        }
        if (mappingInfo!=null) return HandlerMappingImpl(mappingInfo,context)
        return  null
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy