1 回答

TA貢獻1829條經(jīng)驗 獲得超7個贊
struts2中用rest后臺返回json的方法是統(tǒng)一封裝response為JSONObject即可。
舉例如下:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.Action;
public class Test {
public Map responseJson;
public Map getResponseJson() {
return responseJson;
}
public void setResponseJson(Map responseJson) {
this.responseJson = responseJson;
}
public String getList(){
Map<String, Object> map = new HashMap<String, Object>();
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
for(int i=0;i<3;i++){
Map<String, Object> m = new HashMap<String, Object>();
m.put("id", i);
m.put("name", "Mic"+i);
list.add(m);
}
map.put("rows", list);
map.put("totalCont", 3);
this.setResponseJson(map);
return Action.SUCCESS;
}
}
添加回答
舉報