在具有路径变量的单个端点上拥有单独的端点是否有优势?

Is there an advantage to having individual endpoints over a single endpoint with a path variable?

例如,如果我有多种类型的电子设备请求大文件,那么每个设备类型都有单独的端点(或控制器)是否有任何优势(除了可读性和整洁性),如下所示:

@RequestMapping(value = "/device/tablet", method = GET)
    public List<Object> getTabletFile(@RequestBody Object body){
 // code here
}

@RequestMapping(value = "/device/laptop", method = GET)
    public List<Object> getLaptopFile(@RequestBody Object body){
 // code here
}

与此相反:

@RequestMapping(value = "/device/{type}", method = GET)
public List<Object> getFiles(@PathVariable("type") String type, @RequestBody Object body){
 // code here
}

我想知道在性能方面,是否预计系统负载会很高?

TL;DR:别担心。

接受和解析一个新的 HTTP 请求的开销比从 URI 中提取一个路径变量的开销高

Spring MVC 调度例程得到了高度优化;我希望解析路径变量的开销在纳秒级。

当然这也取决于你对控制器内部的type参数做了什么。如果你只是在 switch 语句中使用它,那么它应该很快,如果你再做一些 lookups/logging/case-insensitive matching/etc。那么开销会更高。