技术实践 · 框架解析 · 问题排查 · 最佳实践
在Spring Boot 4.x版本中,官方对路径匹配机制进行了重大调整,移除了旧版的后缀匹配相关API,这给实现`/news/detail/1.html`这类伪静态URL带来了新的挑战。
@Configuration
class WebConfig : WebMvcConfigurer {
override fun configurePathMatch(configurer: PathMatchConfigurer) {
val urlPathHelper = UrlPathHelper()
urlPathHelper.setRemoveSemicolonContent(false)
configurer.setUrlPathHelper(urlPathHelper)
}
}
@GetMapping("/blog/detail/{id}.html")
fun detail(@PathVariable id: Int, model: Model): String {
// 业务逻辑
return "blog/detail"
}