结构
com+- example+- myproject+- Application.java //启动类|+- domain //实体(Entity)与数据库访问层(Repository)| +- Customer.java| +- CustomerRepository.java|+- service 业务| +- CustomerService.java|+- controller 访问控制| +- CustomerController.java|+- config 配置类| +- swagerConfig.java|
注解
@SpringBootApplication
@SpringBootApplicationpublic class HelloWorldApplication {public static void main(String[] args) {SpringApplication.run(HelloWorldApplication.class, args);}}
@EnableAutoConfiguration:启用 SpringBoot 的自动配置机制@ComponentScan: 扫描被@Component(@Service,@Controller)注解的 bean,注解默认会扫描该类所在的包下所有的类。@Configuration:允许在上下文中注册额外的 bean 或导入其他配置类。RESTful Web服务介绍
RESTful Web 服务与传统的 MVC 开发一个关键区别是返回给客户端的内容的创建方式:传统的 MVC 模式开发会直接返回给客户端一个视图,但是 RESTful Web 服务一般会将返回的数据以 JSON 的形式返回,这也就是现在所推崇的前后端分离开发。
<br />Controller
注解
@RestController:返回对象直接JSON或XML写入响应中 = @Controller +@ResponseBody``@RequestParam:url的查询参数值@Pathvairable:获取url中的参数@RequestBody:可将HttpRequest body中的JSON类型反序列化为合适的java类型<br />@RequestMapping、@GetMapping:@Component@ConfigurationProperties@EnableConfigurationProperties:读取指定位置@Validated@NotEmpty@Email
配置
- 优先级
- com.xx.xx.config/xxx.properties
- resource.config/xxx.properties
- resource/xxx.properties
- 指定配置
- @PropertySource(“”)
