我继承了一些基于 struts2 REST-plugin 的代码,下面的结构让我感到困惑:
@Namespace("/merchants/{id}")
public class MerchantAction extends ActionSupport implements ModelDriven<Object> {
private Merchant merchant = new Merchant(); // A Model
private Iterable<Merchant> merchants; // A list of models
....
public HttpHeaders index() {
merchants = merchantService.findAllMerchants();
return new DefaultHttpHeaders("index");
}
@Override
public Object getModel() {
return (merchant != null ? merchant : merchants);
}
public void setId(String id) {
merchant = merchantService.findMerchant(id));
}
换句话说,它似乎在返回列表和返回 getModel() 调用中的单个项目之间切换。这是犹太洁食吗?我觉得有点奇怪