Spring 리 셋 간이 사용

3324 단어 springfirebug
더 읽 기
코드 를 직접 올 리 고 fireforx,F12 를 디 버 깅 합 니 다.firebug 가 설치 되 어 있 으 면 먼저 사용 하지 않 습 니 다:

package com.up360.wechat.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.http.HttpServletRequest;

/**
 *      :
 *
 * @Author: DR.YangLong
 * @Date: 14-7-16
 * @Time:   01:18
 * @Email: [email protected]
 * @Version: 1.0
 * @Module:   :              :
 */
@Controller
@RequestMapping(value = "/redirect")
public class RedirectController {
    //    
    @RequestMapping("/test1")
    public ModelAndView redirect1(){
        ModelAndView mv=new ModelAndView("redirect:/redirect/result.action");
        //  /        ,     forward
        return mv;
    }
    //RedirectView    (  ,       ,  http1.0,      )     (url,false,true,true)。
    //public RedirectView(String url, boolean contextRelative, boolean http10Compatible, boolean exposeModelAttributes)
   @RequestMapping("/test2")
    public RedirectView redirect2(){
        RedirectView redirectView=new RedirectView("/redirect/result.action");
       return redirectView;
    }

    /**
     *     Tomcat server.xml Connector   useBodyEncodingForURI="true"
     *            
     * @return
     */
    @RequestMapping("/test3")
    public ModelAndView redirect3(){
        ModelAndView modelAndView=new ModelAndView("redirect:/redirect/result0.action");
        modelAndView.addObject("msg","ModelAndView       !");
        return modelAndView;
    }

    @RequestMapping("/test4")
    public ModelAndView redirct4(RedirectAttributes redirectAttributes){
       //           ,        ,          
        /*redirectAttributes.addAttribute("msg","ModelAndView       ");*/
        //    session ,           session  ,           ,        
        redirectAttributes.addFlashAttribute("msg", "ModelAndView       ");
        ModelAndView modelAndView=new ModelAndView("redirect:/redirect/result.action");
        return modelAndView;
    }

    @RequestMapping("/result0")
    public @ResponseBody String result(String msg,HttpServletRequest request){
        //     ,        ,    ModelMap
        return "    1        :"+msg;
    }

    @RequestMapping("/result")
    public @ResponseBody String result(ModelMap map,HttpServletRequest request){
        //     ,        ,    ModelMap
        String msg=(String)map.get("msg");
        return "    2        :"+msg;
    }
}

좋은 웹페이지 즐겨찾기