I've used Struts2 to map actions to the methods that return String. Can I use other types? What types are possible to use?
I found that code using a REST plugin
// Handles /orders/{id} GET requests
public HttpHeaders show() {
model = orderManager.findOrder(id);
return new DefaultHttpHeaders("show")
.withETag(model.getUniqueStamp())
.lastModified(model.getLastModified());
}
It shows that it maps to method show that returns HttpHeaders. And it's not a String. How it works?
The framework has features that allows to return not only
String. You can return an instance of theResultdirectly from the action method instead of aString.For exampleIf needed to return multiple types you can set return type as
Object.About the rest method
HttpHeadersis a interface that doesn't extendResult, so it shouldn't be used as a result type.