mirror of
https://github.moeyy.xyz/https://github.com/GeWuYou/forgeboot
synced 2025-11-01 18:08:54 +08:00
Compare commits
No commits in common. "47691cd605c97fe711a3cc47fd27441a1952becf" and "b4c8b6036be041272ddddeaa472dc27a76ed5263" have entirely different histories.
47691cd605
...
b4c8b6036b
@ -1,30 +0,0 @@
|
|||||||
package com.gewuyou.forgeboot.webmvc.version.config.entities;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 版本属性
|
|
||||||
* <p>
|
|
||||||
* 该类用于配置和管理版本相关的属性,通过@ConfigurationProperties注解
|
|
||||||
* 将其与配置文件中以 version 为前缀的属性自动绑定
|
|
||||||
*
|
|
||||||
* @author gewuyou
|
|
||||||
* @since 2025-05-02 11:52:24
|
|
||||||
*/
|
|
||||||
@ConfigurationProperties(prefix = "version")
|
|
||||||
public class VersionProperties {
|
|
||||||
/**
|
|
||||||
* API前缀
|
|
||||||
* <p>
|
|
||||||
* 定义了API的路由前缀,用于在URL中区分不同的API版本
|
|
||||||
*/
|
|
||||||
private String apiPrefix = "/api";
|
|
||||||
|
|
||||||
public String getApiPrefix() {
|
|
||||||
return apiPrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApiPrefix(String apiPrefix) {
|
|
||||||
this.apiPrefix = apiPrefix;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,9 +1,7 @@
|
|||||||
package com.gewuyou.forgeboot.webmvc.version.config
|
package com.gewuyou.forgeboot.webmvc.version.config
|
||||||
|
|
||||||
import com.gewuyou.forgeboot.core.extension.log
|
import com.gewuyou.forgeboot.core.extension.log
|
||||||
import com.gewuyou.forgeboot.webmvc.version.config.entities.VersionProperties
|
|
||||||
import com.gewuyou.forgeboot.webmvc.version.mapping.ApiVersionRequestMappingHandlerMapping
|
import com.gewuyou.forgeboot.webmvc.version.mapping.ApiVersionRequestMappingHandlerMapping
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
|
||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
|
|
||||||
@ -14,7 +12,6 @@ import org.springframework.context.annotation.Configuration
|
|||||||
* @author gewuyou
|
* @author gewuyou
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties(VersionProperties::class)
|
|
||||||
open class VersionAutoConfiguration {
|
open class VersionAutoConfiguration {
|
||||||
/**
|
/**
|
||||||
* 创建并配置一个 ApiVersionRequestMappingHandlerMapping 实例
|
* 创建并配置一个 ApiVersionRequestMappingHandlerMapping 实例
|
||||||
@ -26,8 +23,8 @@ open class VersionAutoConfiguration {
|
|||||||
* @return ApiVersionRequestMappingHandlerMapping 实例,用于处理基于 API 版本的请求映射
|
* @return ApiVersionRequestMappingHandlerMapping 实例,用于处理基于 API 版本的请求映射
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
open fun apiVersionRequestMappingHandlerMapping(versionProperties: VersionProperties): ApiVersionRequestMappingHandlerMapping {
|
open fun apiVersionRequestMappingHandlerMapping(): ApiVersionRequestMappingHandlerMapping {
|
||||||
log.info("创建 API 版本请求映射处理程序映射")
|
log.info("创建 API 版本请求映射处理程序映射")
|
||||||
return ApiVersionRequestMappingHandlerMapping(versionProperties).also { it.order = Int.MIN_VALUE }
|
return ApiVersionRequestMappingHandlerMapping()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,7 +2,6 @@ package com.gewuyou.forgeboot.webmvc.version.mapping
|
|||||||
|
|
||||||
|
|
||||||
import com.gewuyou.forgeboot.webmvc.version.annotation.ApiVersion
|
import com.gewuyou.forgeboot.webmvc.version.annotation.ApiVersion
|
||||||
import com.gewuyou.forgeboot.webmvc.version.config.entities.VersionProperties
|
|
||||||
import org.springframework.core.annotation.AnnotatedElementUtils
|
import org.springframework.core.annotation.AnnotatedElementUtils
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo
|
import org.springframework.web.servlet.mvc.method.RequestMappingInfo
|
||||||
@ -15,9 +14,7 @@ import java.lang.reflect.Method
|
|||||||
* @since 2025-02-04 20:30:44
|
* @since 2025-02-04 20:30:44
|
||||||
* @author gewuyou
|
* @author gewuyou
|
||||||
*/
|
*/
|
||||||
class ApiVersionRequestMappingHandlerMapping(
|
class ApiVersionRequestMappingHandlerMapping : RequestMappingHandlerMapping() {
|
||||||
private val versionProperties: VersionProperties
|
|
||||||
) : RequestMappingHandlerMapping() {
|
|
||||||
/**
|
/**
|
||||||
* 判断是否处理特定类型的Bean
|
* 判断是否处理特定类型的Bean
|
||||||
* 仅处理标注了 @RestController 注解的类
|
* 仅处理标注了 @RestController 注解的类
|
||||||
@ -69,7 +66,7 @@ class ApiVersionRequestMappingHandlerMapping(
|
|||||||
.map {
|
.map {
|
||||||
// 加上版本前缀
|
// 加上版本前缀
|
||||||
RequestMappingInfo
|
RequestMappingInfo
|
||||||
.paths("${versionProperties.apiPrefix}/$it")
|
.paths("/api/$it")
|
||||||
.build()
|
.build()
|
||||||
}.reduce {
|
}.reduce {
|
||||||
// 组合
|
// 组合
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user