无法连接到localhost:8080
1234 | <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId></dependency> |
pom.xml中的这段代码改成
1234 | <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency> |
spring-boot-starter和spring-boot-starter-web的区别:
- spring-boot-starter 是Spring Boot的核心启动器,包含了自动配置、日志和YAML
- spring-boot-starter-web 支持全栈式Web开发,包括Tomcat和spring-webmvc
相关参考
访问localhost:8080时出现Whitelabel Error Page
需要输入在类中输入注解@RequestMapping("/")来映射地址,为了使用@RequestMapping("/"),必须在头部导入org.springframework.web.bind.annotation.RequestMapping包。
@RestController注解等价于@Controller+@ResponseBody的结合,使用这个注解的类里面的方法都以json格式输出,必须在头部导入import org.springframework.web.bind.annotation.RestController包。
若未导入包前已启动项目,需要用maven reimport更新依赖包,不然会报错。