SpringBoot 踩坑记1

页面跳转
window.location.href = "index";

该代码的意思是跳转到 index 这个请求,SpringBoot会根据Controller中的RequestMapping找到"/index"请求,然后执行里面的内容,并不是跳转到"index.html"。


注意 controller 会自动添加controller的前缀 home (即@RequestMapping("home"))
代码如下

@Controller
@RequestMapping("home")
public class Home{
    @RequestMapping(value = "index")
    public ModelAndView index(ModelMap model) {
        return new ModelAndView("home/index",model);
    }
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。