首页 > 代码库 > Spring Boot 精简笔记
Spring Boot 精简笔记
0. Fundamental
a. @SpringBootApplication
b. pom.xml
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.4.RELEASE</version> <relativePath/> </parent> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
1. application.yml (application-dev.yml, application-prod.yml)
spring: profiles: active: prod server: port: 8080 content-path: /demo student: name: Peter age: 19 message: My name is ${student.name}, age is ${student.age} spring: datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/demo username: root password: 123465 jpa: hibernate: dll-auto: update show-sql: true
2. 注入设置值
a. 直接使用单个值:@Value("${student.name}")
b. 注入配置类:
@ConfigurationProperties(prefix = "student")
@Component
3. Controller
a. @Controller: 处理http请求,返回模板文件名 (旧方式)
b. @RestController:处理请求,返回json
@RequestMapping: 配置URL映射
@GetMapping, @PutMapping, @PostMapping, @DeleteMapping
@PathVariable, @RequsetParam
4. Spring-Data-Jpa
a. @Entity
b. @Id
c. Interface class Repository (findOne,findAll,findByXXX,save)
d. @Service, @Transactional
Spring Boot 精简笔记
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。