【发布时间】:2020-05-27 00:26:00
【问题描述】:
我很好奇返回相同资源但使用不同 DTO 的最佳方式是什么。 例如,我有一个用户类:
public class User {
private String name;
private String surname;
private String age;
}
用户列表在 url 下可用:
/users
其他一些视图需要用户列表但没有年龄,所以,我想返回 UserDTO 列表。
public class UserDTO {
private String name;
private String surname;
}
定义url的正确方法是什么?
/userDtos - this is bad, because I can have more than one DTOs for representing users,
/users/dto - this is also bad
/users?name=true,surname=true - this one is also bad, it indicates that we are filtering the result, but we are not; we're just filtering fields.
肯定有人以前遇到过这个问题,但我在互联网上找不到任何东西。
【问题讨论】:
标签: rest naming-conventions naming