控制器代碼以下所示:web
import org.springframework.web.bind.annotation.GetMapping; public class HelloController { @GetMapping(value="/hello") public Object hello() { return "Hello Mango!"; } }
啓動器代碼以下所示:spring
@SpringBootApplication public class MangoAdminApplication { public static void main(String[] args) { SpringApplication.run(MangoAdminApplication.class, args); } }
項目可正常啓動不報錯,可是訪問hello頁面時,報錯內容以下所示app
出錯緣由:spa
控制器類沒有添加RestController註解code
解決方法:blog
在控制器類中添加註解io
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping(value="/hello") public Object hello() { return "Hello Mango!"; } }
成功運行class