java - 如何使用控制器制作像 /{Country}/{city in this country}/ 这样的链接
问题描述
我在我的应用程序中使用控制器。我使用了@RequestMapping,但我无法用它解决这个问题:假设我的数据库中有一个包含国家列表的表,以及一个包含城市列表的表(一个国家与城市是一对多的连接)。我怎样才能确保当我点击一个国家时,我会转到这个国家的城市列表,链接就像 / 俄罗斯 / 莫斯科 ps 抱歉英语不好
解决方案
遵循良好的端点构建实践应该是这样的:
@GetMapping("/countries/{country}/cities")
public ResponseEntity<?> listCitiesByIdCountry(@PathVariable long country) {
//Code for get Cities for that idCountry
return ResponseEntity.ok(list);
}
推荐阅读
- vim - 在 Vim 中用新行替换空格
- javascript - 如何在另一个文件中使用 vue 路由器?
- c# - 向asp.net web api项目中手动创建的startup.cs类添加配置
- ruby-on-rails - ruby葡萄实体——继承,子不包含父的字段
- flutter - 未处理的异常:不支持的操作:通用 DartType 的序列化:UnknownType(?) (UnknownType)
- django - 如何在 Angular 9 中传递 Django rest Framework API?
- postgresql - 如果我需要等待连接,我应该做主异步吗?
- python - 如何找到多条线与曲线的交点?
- python - Airflow 操作员是否需要返回任何内容才能正常运行?
- python - 计算子串计数