请求使用特殊字符映射类似于谷歌地图的属性



我正在使用 Spring boot,我想以类似于 Google 地图的方式传递两个双精度值:而不是使用/api?x=1.1&y=2.2 并获取我想做的请求参数:/api/@1.1,2.2

在控制器级别,如何从第二个 get 请求中获取这两个参数?

@GetMapping("/api/@{term:.+}")
public void index(@PathVariable String term) {
    // term is whatever after the "@"
    // you can parse the term to what you want
    // {term:.+} is a regex mapping for including the last dot
}

例如
如果您要求../api/@1.1,2.2
术语将为"1.1,2.2"。
用","拆分术语,并将字符串转换为双精度。

相关内容

最新更新