我有以下问题:
我有一个 Rest 控制器,我想在以下 URL 中配置它:
/api/districts/1,2,3 - (按 id 数组列出地区)
/api/districts/1 - (按单个 id 列出地区)
这些是以下映射方法:
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public District getById(@PathVariable int id) {
// check input
return districtService.getById(id);
}
@RequestMapping(value = "/{districtIDs}", method = RequestMethod.GET)
public List<District> listByArray(@PathVariable Integer[] districtIDs) {
ArrayList<District> result = new ArrayList<>();
for (Integer id : districtIDs) {
result.add(districtService.getById(id));
}
return result;
}
这是我向/api/districts/1,2,3发出请求时遇到的错误
There was an unexpected error (type=Internal Server Error, status=500).
Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/districts/1,2,3': {public java.util.List com.groto.server.web.DistrictsController.listByArray(java.lang.Integer[]), public com.groto.server.models.hibernate.District com.groto.server.web.DistrictsController.getById(int)}
这是我向/api/districts/1发出请求时遇到的错误
There was an unexpected error (type=Internal Server Error, status=500).
Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/districts/1': {public java.util.List com.groto.server.web.DistrictsController.listByArray(java.lang.Integer[]), public com.groto.server.models.hibernate.District com.groto.server.web.DistrictsController.getById(int)}
慕村9548890
相关分类