Spring mvc 跳转

package com.springapp.mvc;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
//标示本类为处理器
@RequestMapping("/")
//处理请求的url与“/”想匹配
public class HelloController {
    @RequestMapping(method = RequestMethod.GET)
    public String printWelcome(ModelMap model) {
        model.addAttribute("message", "Hello world!");
        return "hello";
        /** * 与mvc-dispatcher-servlet.xml的配置有关 * 在本项目中,mvc-dispatcher-servlet.xml配置是 * <property name="prefix" value="/WEB-INF/pages/"/> * <property name="suffix" value=".jsp"/> * 为映射到"/WEB-INF/pages/"下以".jsp"结尾的文件 * return "hello"便是去寻找在page文件夹下 * 以JSP结尾,名为hello的文件 * (也就是ModleAndView) */


    }
}

其中的return的形式根据形式分为两种
—转发 return “forward:/xxx/xxx”
—重定向 return”redirect:/xxxx”

为了避免表单的重复提交
可以用RedirectAttributes进行避免

你可能感兴趣的:(spring,mvc)