【SpringMVC】03.转发与重定向【个人用笔记】

1,转发

@Controller
@RequestMapping("/hello")
public class Demo1 {
    @RequestMapping("test1")
    public String test1() {
        System.out.println("你好mvc1");
        return "forward:/hello2/demo1.jsp";
    }
    @RequestMapping("test2")
    public String test2() {
        System.out.println("你好mvc2");
        return "/hello2/demo1.jsp";
    }
}

2,重定向

    @RequestMapping("test1")
    public String test1() {
        System.out.println("你好mvc1");
        return "redirect:/go1.jsp";
    }
    @RequestMapping("test1")
    public String test1() {
        System.out.println("你好mvc1");
        return "redirect:test1"; // 重定向到test1方法上
    }

3,补充细节

  • 增删改用重定向
  • 查询用转发

4,视图解析器

mxv.xml配置

作用:获取到后端的返回值后,在前后拼接,/xxx.jsp

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- 前缀 -->
        <property name="prefix" value="/"/>
        <!-- 后缀 -->
        <property name="suffix" value=".jsp"/>
    </bean>

java测试

@Controller
@RequestMapping("/hello")
public class Demo1 {
    @RequestMapping("/test1")
    public String test1() {
        return "go";
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值