mirror of
https://github.moeyy.xyz/https://github.com/GeWuYou/forgeboot
synced 2025-10-28 02:36:39 +08:00
feat(version): Cross-domain configuration is supported for API version request mappings
- Inject VersionProperties and CorsConfigurationSource in VersionAutoConfiguration - Updated the apiVersionRequestMappingHandlerMapping method to add support for cross-origin configuration - Remove unnecessary comments from R classes
This commit is contained in:
parent
9cdc962d9a
commit
0920a83e1c
@ -18,7 +18,7 @@ data class R<T>(
|
|||||||
val message: String,
|
val message: String,
|
||||||
val data: T? = null,
|
val data: T? = null,
|
||||||
val requestId: String? = null,
|
val requestId: String? = null,
|
||||||
val extra: Map<String, Any?> = emptyMap() // ✅ 扩展字段保存位置
|
val extra: Map<String, Any?> = emptyMap()
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* 转换为可变 Map,包含 extra 中的字段
|
* 转换为可变 Map,包含 extra 中的字段
|
||||||
@ -33,7 +33,7 @@ data class R<T>(
|
|||||||
if (!requestId.isNullOrBlank()) {
|
if (!requestId.isNullOrBlank()) {
|
||||||
map["requestId"] = requestId
|
map["requestId"] = requestId
|
||||||
}
|
}
|
||||||
map.putAll(extra) // ✅ 扁平化合并
|
map.putAll(extra)
|
||||||
return map
|
return map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,8 @@ import com.gewuyou.forgeboot.webmvc.version.mapping.ApiVersionRequestMappingHand
|
|||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
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
|
||||||
|
import org.springframework.web.cors.CorsConfigurationSource
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*版本自动配置
|
*版本自动配置
|
||||||
@ -15,7 +17,10 @@ import org.springframework.context.annotation.Configuration
|
|||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties(VersionProperties::class)
|
@EnableConfigurationProperties(VersionProperties::class)
|
||||||
open class VersionAutoConfiguration {
|
open class VersionAutoConfiguration(
|
||||||
|
private val versionProperties: VersionProperties,
|
||||||
|
private val corsConfigurationSource: CorsConfigurationSource
|
||||||
|
) : WebMvcConfigurer {
|
||||||
/**
|
/**
|
||||||
* 创建并配置一个 ApiVersionRequestMappingHandlerMapping 实例
|
* 创建并配置一个 ApiVersionRequestMappingHandlerMapping 实例
|
||||||
*
|
*
|
||||||
@ -26,8 +31,11 @@ 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(versionProperties).also {
|
||||||
|
it.order = Int.MIN_VALUE
|
||||||
|
it.corsConfigurationSource = corsConfigurationSource
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user