Whitelabel Error Page访问

运行springboot的时候访问接口报错,如上图所示,后端controller层代码如下:

package com.hu.sprintboot01.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/hello")
public class HelloController {
    @GetMapping("/hello")
    @ResponseBody
    public String hello(){
        return "hello";
    }
}

访问localhost:8080/hello/hello地址却会报异常,后面发现是异常原因是因为IDEA目录结构的问题,Application启动类的位置不对,要将Application类放在最外侧,即包含所有子包 。而我的controller则放在了最外层的包里面。导致找不到页面。

 修改完controller层 的位置之后再次访问该接口,页面显示正常。

 

猜你喜欢

转载自blog.csdn.net/qq_56728342/article/details/125382050