[TOC]
@RestController 与@Controller类似,告知sprint这是个类是用来处理web请求的,不同的是,@RestController告诉spring将结果直接渲染到调用端并显示,功能相当于@Controller和@ResponseBody结合
@Controller
@RestController
@ResponseBody
@EnableAutoConfiguration
SpringBootApplication 等于 @Configuration,@EnableAutoConfiguration 和@ComponentScan三个注解的结合
@Configuration
@ComponentScan
在webapp中,通常我们会把静态文件放在/webapp目录下, 但是这个目录只是在我们war包的时候有效。 使用spring-boot,将运行程序打为jar包的时候,常见的是将静态文件放在/src/main/resources/static
需要将springBootApplication设置为非web环境
springBootApplication
springBootApplication.setWebEnvironment(false)
或者设置applicationContextClass属性
applicationContextClass
你执行的逻辑层实现CommandLineRunner接口,如果有多个逻辑层的类,你可以通过order注解来指定执行的顺序
CommandLineRunner
order
ApplicationRunner和CommandLineRunner在SpringApplication启动之前执行
ApplicationRunner
SpringApplication
Last updated 7 years ago
Was this helpful?