【视频笔记】Spring boot入门级笔记
2017-10-02 本文已影响8人
老胡聊聊天
该笔记是看视频的记录,视频地址:http://www.imooc.com/learn/767
一、sb简介
1、springboot让编码、配置、部署、监控变得更简单。

2、sb可以认为是springMVC的升级版

3、spring的特点:
- 化繁为简
- 下一代框架

- 入门级微框架:微服务springcloud

二、第一个sb程序

几种方式启动sb程序:
- run main方法
- mvn spring-boot:run
- java 方式启动
mvn install
cd target
java -jar xx.jar
三、自定义属性配置
1、yml方式配置

然后使用@Value注释进行注入,其中cupSize和age是单一属性,content是对象属性

2、配置类
属性太多的情况下,可以使用一个配置bean来获取
@Component
@ConfigurationProperties(prefix="girl")

然后autowired的进来即可

3、多环境配置
在实际项目中,开发环境、测试环境、生产环境可能使用不同配置
我们可以做多套配置,然后在主配置文件中指定需要使用的配置

使用java -jar方式启动的时候,也可以直接指定参数
java -jar target/xx.jar --spring.profiles.active=prod
此外,写在主文件中的配置,多种环境都可以用到

四、controller的使用
1、@Controller
处理http请求,必须配合一个模板来使用,对性能有损耗,目前使用RestController比较多
2、@RestController
spring4之后新加的,等于原来的@ResponseBody+@Controller
3、@RequestMapping配置url映射



另外RequestMethod,如果不写,默认get和post都可以访问,但是不建议这样使用。
可以用postman工具调试rest请求
4、PathVariable
获取url中的数据

5、RequestParam
获取请求的参数的值



6、GetMapping
组合注解

五、spring-data-jpa
1、JPA(Java Persistence API)定义
JPA定义了一系列对象持久化的标准,目前实现这一规范的有Hibernate、TopLink。
spring-data-jpa就是对spring对hibernate的整合。
2、先设计一下restful API

3、配置mysql和jpa

4、开发这几个API





六、事物管理
