springboot使用事务
Spring Boot 使用事务非常简单,底层依然采用的是 Spring 本身提供的事务管理
➢ 在入口类中使用注解 @EnableTransactionManagement
开启事务支持(springboot其实会自动帮你添加好,加不加都行)➢ 在访问数据库的 Service 方法上添加注解
@Transactional 即可(这个需要自己手动加,不然事务不会回滚)
Spring Boot 下的 Spring MVC注释
-
@Controller
Spring MVC 的注解,处理 http 请求,放在控制类前面,给中央控制器扫描 -
@RestController
Spring 4 后新增注解,是@Controller 注解功能的增强 是 @Controller 与@ResponseBody 的组合注解
如果一个 Controller 类添加了@RestController,那么该 Controller
类下的所有方法都相当于添加了@ResponseBody 注解 用于返回字符串或 json 数据
- @RequestMapping(常用)
支持 Get 请求,也支持 Post 请求
- @GetMapping
RequestMapping 和 Get 请求方法的组合 只支持 Get 请求 Get 请求主要用于查询操作
- @PostMapping
RequestMapping 和 Post 请求方法的组合 只支持 Post 请求 Post 请求主要用户新增数据
- @PutMapping
RequestMapping 和 Put 请求方法的组合 只支持 Put 请求 Put 通常用于修改数据
- @DeleteMapping
RequestMapping 和 Delete 请求方法的组合 只支持 Delete 请求 通常用于删除数据
推荐一个小工具:PostMan非常好用而且强大,以后公司会用的上,专门哪来当测试,支持各种请求
链接:
官网,https://www.getpostman.com(需趴)
非官网,Postman 4.1.2 下载地址: http://files.cnblogs.com/files/mafly/postman-4.1.2.rar
(这是谷歌浏览器插件,需要手动导入,详情百度)