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
时间: 2024-10-05 05:00:58