hanhx1993
匿名用户123
2017-12-17 08:13

后台用这种方式返回数据到ftl,有问题吗,list为什么取不到值

5
  • freemarker

@RequestMapping(value = "/project/p_list.do", method={RequestMethod.POST, RequestMethod.GET})
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView mv = new ModelAndView("test2");

    String token = request.getParameter("token");
    String page = request.getParameter("page");
    String upStatu=request.getParameter("upStatu");
    String statu=request.getParameter("statu");

    String loginUrl = "http://10.0.2.14:8080/zfs_pg/project/p_list.do?";
    String url = loginUrl + "token="+ token ;//+ "&page=" + page + "&upStatu=" + upStatu + "&statu=" + statu; 

    String result = null;
    try {
        result = HttpUtils.URLPost(url);
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace(); 
    }
    System.out.println(result);

    JSONObject  jsonObject = new JSONObject(result);
    int ret = jsonObject.getInt("ret");
    List<Project> pList = new ArrayList<Project>();
    if(ret==0){ 
        JSONObject  jsonObject2 = jsonObject.getJSONObject("data");
        JSONArray plist = jsonObject2.getJSONArray("plist"); 

        for (int i = 0; i < plist.length(); i++) {
            JSONObject pC = plist.getJSONObject(i);
            int pid = pC.getInt("pid");
            String title = pC.getString("title");
            String content = pC.getString("content");
            String type = pC.getString("type");
            String pTime = pC.getString("pTime");
            String endTime = pC.getString("endTime");
            String uName = pC.getString("uName");
            Project pc = new Project();
            pc.setPid(pid);
            pc.setContent(content);
            pc.setTitle(title);
            //pc.setpTime(pTime);
            pList.add(pc);
        }           
    }else{
        String msg = jsonObject.getString("msg");
    }



    mv.addObject("plist", pList);
    return mv;

}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答