1 学习计划
1. Springboot和springmvc的关系
2. 第一个springboot程序的编写
3. 自定义属性配置
4. Controller的使用
5. Spring-data-jpa
6. 事务的管理
2 Springboot的特点
1. 简化配置
2. 是新一代的框架,未来的趋势
3. 微服务架构的基础
3 springboot的第一个应用
- 创建springboot工程
- 启动项目
编写helloController
@RestControllerpublic class HelloController {
@RequestMapping("/hello")
public String sayHello() {
return "hello spring boot";
}
}
4 属性配置
配置项目的端口和访问名称
使用官网推荐的配置文件 yml
绑定配置文件的内容到类的属性
优化之后
配置文件的属性切换
5 controller的使用
Restful:http://localhost:8082/demo10/users.do?id=1
http://localhost:8082/demo10/users/1
使用PathVariable实现restful风格的请求
@RequestMapping(value = "/haha/{id}",method = RequestMethod.POST) public String haha(@PathVariable("id") Integer id) { return "id: "+id; }
6 数据库的操作
restfulAPI的设计
请求类型 | 请求路径 | 功能 |
GET | /users | 获取用户列表 |
POST | /users | 创建一个用户 |
GET | /users/id | 用过编号查询用户 |
PUT | /users/id | 用过编号更新用户 |
DELETE | /users/id | 用过编号删除用户 |
使用spring-data-jpa
配置
创建数据库,配置pojo
代码的编写