如何在Spring Controller中指向不同的JSP页面

时间:2014-01-02 11:35:45

标签: spring jsp controller

我有4个不同页面的标签。 (pageOne,pageTwo,pageThree,pageFour)。但是如何在此编码,它只指向 pageOne

当Tab =“2”的值时,我希望它指向 pageTwo

当Tab =“4”时

pageThree ,当Tab =“4”时, pageFour

以下是Controller。有人可以帮忙吗?

Controller

@RequestMapping(value="/encodeListAjax")
public String encodeListAjax(
        HttpServletResponse response,
        HttpServletRequest request,
        ModelMap model,
        Condition condition,
        @RequestParam Map<String, Object> maps, 
        @ModelAttribute Encode encode) throws Exception { 

if(encode.getTab() != null && !"".equals(encode.getTab())) {
        if("1".equals(encode.getTab())) {
            String[] prcsSteCds = {"R02","R05","R06"};
            maps.put("prcsSteCd", prcsSteCds);
        } else if("2".equals(encode.getTab())) {
            String[] prcsSteCds = {"R03"};
            maps.put("prcsSteCd", prcsSteCds);
        } else if("3".equals(encode.getTab())) {
            String[] prcsSteCds = {"R04"};
            maps.put("prcsSteCd", prcsSteCds);
        } else if("4".equals(encode.getTab())) {
            String[] prcsSteCds = {"R07"};
            maps.put("prcsSteCd", prcsSteCds);
        }
    } else {
        String[] prcsSteCds = {"R02","R05","R06"};
        maps.put("prcsSteCd", prcsSteCds);
    }

    List<Encode> resultList = EncodeRepository.encCurList(maps);    
    Long resultformCnt = EncodeRepository.encCurListCnt(maps);
    Pagination<Encode> resultListCnt = PaginationUtil.getPaginationList(resultList, condition, resultformCnt, Order.DESC);              

    model.addAttribute("resultList", resultList);
    model.addAttribute("resultformCnt", resultformCnt);
    model.addAttribute("resultListCnt", resultListCnt);
    model.addAttribute("condition", condition);         

       return "empty/admin/survMng/survey/pageOne";
}

1 个答案:

答案 0 :(得分:2)

您的控制器处理程序方法可能如下所示,以实现TAB切换的目标

@RequestMapping(value="/encodeListAjax")
public String encodeListAjax(
        HttpServletResponse response,
        HttpServletRequest request,
        ModelMap model,
        Condition condition,
        @RequestParam Map<String, Object> maps, 
        @ModelAttribute Encode encode) throws Exception { 

if(encode.getTab() != null && !"".equals(encode.getTab())) {

       int redirectPage=encode.getTab();
       String[] prcsSteCds=null;
       if("1".equals(encode.getTab())) {
            prcsSteCds = {"R02","R05","R06"};
        } else if("2".equals(encode.getTab())) {
            prcsSteCds = {"R03"};
        } else if("3".equals(encode.getTab())) {
            prcsSteCds = {"R04"};
        } else if("4".equals(encode.getTab())) {
            prcsSteCds = {"R07"};
        }
    } else {
        prcsSteCds = {"R02","R05","R06"};
    }
    maps.put("prcsSteCd", prcsSteCds);
    List<Encode> resultList = EncodeRepository.encCurList(maps);    
    Long resultformCnt = EncodeRepository.encCurListCnt(maps);
    Pagination<Encode> resultListCnt = PaginationUtil.getPaginationList(resultList, condition, resultformCnt, Order.DESC);              
    model.addAttribute("resultList", resultList);
    model.addAttribute("resultformCnt", resultformCnt);
    model.addAttribute("resultListCnt", resultListCnt);
    model.addAttribute("condition", condition);         


      if("1".equals(redirectPage)){
           return "empty/admin/survMng/survey/pageOne";
       }else if("2".equals(redirectPage)){
           return "empty/admin/survMng/survey/pageTwo";
       }else if("3".equals(redirectPage)){
           return "empty/admin/survMng/survey/pageThree";
       }else if("4".equals(redirectPage)){
          return "empty/admin/survMng/survey/pageFour";
       }else
         return "empty/admin/survMng/survey/Default";
       }
    return "empty/admin/survMng/survey/NoFound";
}