@SpringBootApplication
申明让 spring boot 自动给程序进行必要的配置,这个配置等同于:@Configuration ,@EnableAutoConfiguration 和 @ComponentScan(“包路径”) 三个配置。
@SpringBootApplication // 这个一个springboot应用,主程序类
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class,args);//创建SpringApplication对象调用run方法
}
}
@Controller、@ResponseBody、@RestController和@ResponseMapping
@Controller:用于定义控制器类,在 spring 项目中由控制器负责将用户发来的 URL 请求转发到对应的服务接口(service 层)
@ResponseBoby:将controller的方法返回的对象通过适当的转换器转换为指定的格式之后,写入到response对象的body区,通常用来返回JSON数据或者是XML
@RestController:@ResponseBody 和 @Controller 的合集
@ResponseMapping:映射请求,也就是通过它来指定控制器可以处理哪些URL请求
@Controller
//@RestController
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String handle01(){
return "Hello ,spring boot";
}
}