Spring MVC 主页控制器的根URL“/”出现http错误404

g9icjywg  于 2022-11-14  发布在  Spring
关注(0)|答案(1)|浏览(120)

我定义了一个控制器,使用:

@Controller
@RequestMapping("/")
public class HomePageController {
    
    @RequestMapping(method = RequestMethod.GET)
    public String home(@RequestParam(value = "logout", defaultValue = "false") final boolean logout, final Model model, final RedirectAttributes redirectModel, final HttpServletRequest request, final HttpServletResponse response) {
 System.out.println("testing");return "homepage";
}

该控件甚至不会访问此处定义的home方法并给出响应:
HTTP状态404 -未找到
但是,当我将请求Map更改为@RequestMapping("/test")时,我能够在上面定义的home方法中获得控制权。
当请求Map用“/"定义时,为什么我不能点击控制器?我需要根URL来登录主页。

qhhrdooz

qhhrdooz1#

试试这个

删除HomePageController上面的@RequestMapping("/"),并添加上面的特定方法签名,如下所示

public class HomePageController {
    
    @RequestMapping(method = RequestMethod.GET,path="/")
     public String home(@RequestParam(value = "logout", defaultValue = "false")....

}

应该行得通!

相关问题