我尝试为特定API终结点隐藏对象的几个字段。
例如:
"student": {
"name": "value1",
"age": "value2",
"dob": "value3",
"value": "value4"
}我需要为某些API端点提供和隐藏这些值。
接口1: GET : /school/student/personal
"student": {
"name": "value1",
"age": "value2"
}接口2: GET : /school/student/all
"student": {
"name": "value1",
"age": "value2",
"fatherName": "value3",
"motherName": "value4",
}发布于 2021-07-08 17:55:26
对于我来说,您使用的是不同的对象,您可以创建DTO (数据传输对象),并使您的API返回DTO。
您需要适配器将域对象(ex.Student)转换为DTO对象(StudentDTO或TinyStudentDTO)
例如。
接口1: GET : /school/student/personal应返回TinyStudentDTO
TinyStudentDTO
-name
-age接口2: GET : /school/student/all返回StudentDTO
您的StudentDTO将使用TinyStudent进行扩展
StudentDTO
-fatherName
-motherNamehttps://stackoverflow.com/questions/68299241
复制相似问题