配置
- 修改maven配置文件setting.xml,使用阿里云镜像加快镜像下载。
- 导约束
<parent>
<!--父项目用于作依赖管理,自动版本仲裁机制-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
自定义版本示例
<properties>
<mysql.version>5.1.43</mysql.version>
</properties>
- 包扫描
- 主程序所在包及其下面的所有子包里面的组件都会被默认扫描进来
- 改变扫描路径:在主程序添加注解
@SpringBootApplication(scanBasePackages=**"com.atguigu"**)`或`@ComponentScan
基本注解
- @SpringBootApplication:
表明是一个SpringBoot应用,直接运行
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class,args);
}
}
- @ResponseBody:
返回一个字符串,而不是解析成一个页面
- @RestController:
=@ResponseBody+@Controller
//@Controller
//@ResponseBody
@RestController
public class HelloController {
@RequestMapping("/hello")
public String handle01(){
return "Hello,Spring Boot 2!";
}
}