springmvc中RequestMapping注解和redirect路径加不加斜杠有何区别

RequestMapping注解和redirect路径加不加斜杠有何区别

1.redirect 重定向时是否需要加"/"斜杠

项目的根路径为:http://localhost:8080/vueblog

页面请求/user/login之后重定向到 /index.jsp

@Controller
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/login")
    public String testPath(){
        return "redirect:/index.jsp";
    }
}
如果 redirect之后没有添加斜杠,就会使用当前controller的相对路径
    访问的是:http://localhost:8080/vueblog/user/index.jsp

在这里插入图片描述

如果 redirect之后添加了斜杠,就会拼接项目的根路径 
    访问的是:http://localhost:8080/vueblog/index.jsp

在这里插入图片描述

2.关于RequestMapping注解中的value是否加斜杠

可加可不加,因为在springmvc底层会对其进行处理,如果没有斜杠会自动加上

源码:
org.springframework.web.servlet.mvc.condition.PatternsRequestCondition prependLeadingSlash
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值