首页 > 解决方案 > 如何为特定情况设计rest uri?

问题描述

我有一个通过 EmployeeController 由 rest api 管理的员工列表。

很少的 URI——

/employees - Get all employees

/employees/1 - Get employee with id 1

Employee 有一个具有deptId的对象 Department 。

现在我想创建 URI 来获取所有具有 deptId = 30 和 dateofBirth > '01-01-1990' 的员工

为这种情况编写 URI 的最佳方法是什么?

标签: restspring-bootspring-mvccontroller

解决方案


使用查询参数/employees过滤将返回哪个员工的常见做法。

例如 :

  • /employees?deptId=30只返回部门为 30 的员工
  • /employees?dateofBirth=19900101仅返回 DOB 为 1990 年 1 月 1 日的员工
  • /employees?deptId=30&dateofBirth=19900101同时满足上述条件的员工返岗。

推荐阅读