首页 > 编程语言 > 详细

Spring Boot 精简笔记

时间:2017-07-16 18:47:34      阅读:238      评论:0      收藏:0      [点我收藏+]

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 精简笔记

原文:http://www.cnblogs.com/pekkle/p/7191239.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!