public class Response<T> {
private boolean status;
private String message;
private T body;
...
}
When to use:
Response response = new Response<String>();
But personally I don’t like this approach very much. It is recommended that when it succeeds, the response returns the entity you want to return; when it fails, it returns an error entity. As for the return value, just use http status directly. This is closer to RESTful
Use template classes
When to use:
But personally I don’t like this approach very much. It is recommended that when it succeeds, the response returns the entity you want to return; when it fails, it returns an error entity. As for the return value, just use http status directly. This is closer to RESTful
Put a base class and put the common attributes into this base class, and then other responses can inherit this class
Actually, I think this requirement should be met with
HttpServletResponseWrapper
this thing. I don’t know if you can understand it now