Generally speaking, you can define a return format as follows. resultCode定义了多种返回类型,比如除了resultCode为0其他均为错,且errorMsg有具体说明,正常业务的返回对象由result描述,在里面我们可以定义正常逻辑的多种返回类型,比如可以用resultType表示不同的类型,多个字段分别包装不同类型结果,如果差别不大,不一定需要多个字段,一个字段即可(里面的字段内容可以为null).
If it is http, you can use the header to pass the format of the request, and then the interface determines the format of the corresponding response. Non-HTTP is also similar. The caller provides the required format or field, and the server can provide different results according to the identification.
Use generics to define a return object
Generally speaking, you can define a return format as follows.
resultCode
定义了多种返回类型,比如除了resultCode
为0
其他均为错,且errorMsg
有具体说明,正常业务的返回对象由result
描述,在里面我们可以定义正常逻辑的多种返回类型,比如可以用resultType
表示不同的类型,多个字段分别包装不同类型结果,如果差别不大,不一定需要多个字段,一个字段即可(里面的字段内容可以为null
).If it is http, you can use the header to pass the format of the request, and then the interface determines the format of the corresponding response. Non-HTTP is also similar. The caller provides the required format or field, and the server can provide different results according to the identification.