1. 程式人生 > >Spring Boot 精簡筆記

Spring Boot 精簡筆記

depend done 1.5 文件名 use date eas path 模板

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. 註入配置類:
[email protected](prefix = "student")
[email protected]

3. Controller
  a. @Controller: 處理http請求,返回模板文件名 (舊方式)
  b. @RestController:處理請求,返回json
[email protected]: 配置URL映射
[email protected], @PutMapping, @PostMapping, @DeleteMapping
[email protected], @RequsetParam

4. Spring-Data-Jpa
  a. @Entity
  b. @Id
  c. Interface class Repository (findOne,findAll,findByXXX,save)
  d. @Service, @Transactional

Spring Boot 精簡筆記