Whitelabel Error Page错误如何解决?

main.java:

package cn.lai.dolphinMusic;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class musicMain {
    public static void main(String [] args){
        SpringApplication.run(musicMain.class,args);
    }
}

controller:

package cn.lai.dolphinMusic.Controller;

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

@Controller
public class test {
    @RequestMapping("/hello")
    public String sayHi(String name){
        return "Hello, "+name;
    }
}

application.yml:

server:
  port: 8880
  servlet:
    context-path: /

项目可以正常启动
访问http://localhost:8880/hello?name=lai

得到的结果是:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Jun 16 11:32:35 CST 2021
There was an unexpected error (type=Not Found, status=404).
No message available

如何解决?

阅读 9.3k
1 个回答

控制类注解@Controller改为@RestController

你写的注解默认返回的是页面

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题