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
如何解决?
控制类注解@Controller改为@RestController
你写的注解默认返回的是页面