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