接上篇
controller中
@Controller
@RequestMapping("/moblieCategory")
public class Moblie_CategoryController {
@RequestMapping("/category")
public String mobileHomeCategory(Model model){
String url="xxxx/mobile/category";
String homeDataJsonArrayString=Moblie_Utils.loadJson(url);
JSONObject jsonObject=null;
jsonObject= JSON.parseObject(homeDataJsonArrayString);
MobileCategory category = new MobileCategory();
List<MobileBigCategory> mobileBigCategoryList=new ArrayList<MobileBigCategory>();
ArrayList<MobileSmallCategory> mobileSmallCategoryList=null;
MobileBigCategory bigCategory=null;
MobileSmallCategory mobileSmallCategory=null;
JSONArray dataArray=null;
JSONArray childrenArray=null;
dataArray=jsonObject.getJSONArray("data");
for(int i=0;i<dataArray.size();i++){
bigCategory=new MobileBigCategory();
jsonObject=dataArray.getJSONObject(i);
bigCategory.setId(Integer.parseInt(dataArray.getJSONObject(i).getString("id")));
bigCategory.setName(dataArray.getJSONObject(i).getString("name");
childrenArray=dataArray.getJSONObject(i).getJSONArray("children";
if(childrenArray!=null && childrenArray.size()>0) {
mobileSmallCategoryList = new ArrayList<MobileSmallCategory>();
for (int j = 0; j < childrenArray.size(); j++) {
mobileSmallCategory = new MobileSmallCategory();
mobileSmallCategory.setId(Integer.parseInt(childrenArray.getJSONObject(j).getString("id")));
mobileSmallCategory.setName(childrenArray.getJSONObject(j).getString("name"));
mobileSmallCategory.setChildren(childrenArray.getJSONObject(j).getString("children"));
mobileSmallCategory.setParentId(Integer.parseInt(childrenArray.getJSONObject(j).getString("parentId")));
mobileSmallCategory.setImgUrl(childrenArray.getJSONObject(j).getString("image"));
mobileSmallCategory.setBannerUrl(childrenArray.getJSONObject(j).getString("banner"));
mobileSmallCategory.setType(childrenArray.getJSONObject(j).getString("type"));
mobileSmallCategory.setFirstChar(childrenArray.getJSONObject(j).getString("first_char"));
mobileSmallCategory.setEnabled(childrenArray.getJSONObject(j).getString("enabled"));
mobileSmallCategoryList.add(mobileSmallCategory);
}
}
bigCategory.setChildren(mobileSmallCategoryList);
bigCategory.setParentId(Integer.parseInt(dataArray.getJSONObject(i).getString("parentId")));
bigCategory.setImgUrl(dataArray.getJSONObject(i).getString("image"));
bigCategory.setImgUrl(dataArray.getJSONObject(i).getString("banner"));
bigCategory.setType(dataArray.getJSONObject(i).getString("type"));
bigCategory.setFirstChar(dataArray.getJSONObject(i).getString("first_char"));
bigCategory.setEnabled(dataArray.getJSONObject(i).getString("enabled"));
mobileBigCategoryList.add(bigCategory);
}
model.addAttribute("mobileBigCategoryList",mobileBigCategoryList);
return "mobileCategory.category";//跳转的tiles(jsp)