springboot-day5 整合mybaits 实现数据持久层crud操作以及添加事务
1.1添加
@Insert("INSERT INTO tb_user(name,phone,create_time,age) VALUES(#{name}, #{phone}, #{createTime},#{age})")
@Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id") //keyProperty java对象的属性;keyColumn表示数据库的字段
int insert(User user);
1.2.查询
@Select("SELECT * FROM tb_user")
@Results({
@Result(column = "create_time",property = "createTime") // @results作用将create_time和createTime绑定作映射
})
List<User> getAll();
@Select("SELECT * FROM user WHERE id = #{id}")
@Results({
@Result(column = "create_time",property = "createTime")
})
User findById(Long id);
1.3.修改
@Update("UPDATE user SET name=#{name} WHERE id =#{id}")
void update(User user);
1.4.删除
@Delete("DELETE FROM user WHERE id =#{userId}")
void delete(Long userId);
1.5.添加事务
@Transactional(propagation=Propagation.REQUIRED)
public int addAccount() {
User user = new User();
userMapper.insert(user);
int i = 19/0;
return 0;
}
相关文章
- SpringBoot自动装配原理(附面试快速答法)
- Springboot启动后报错【This application has no explicit mapping for /error, so you are seeing this as a fallback····】
- SpringBoot+Shiro引起事务失效、错误原因、解决方法
- springboot web开发crud操作方法名的Api
- 第十二章 springboot + mongodb(复杂查询)
- springboot 定时表达式
- springboot创建多环境profile打包
- springboot+mysql实现的电影资讯网站
- Linux下部署springboot项目的步骤及过程
- SpringBoot 通过jjwt快速实现token授权
- Springboot 使用nacos鉴权的简单步骤
- 后端 SpringBoot + 前端 vue 打包发布到Tomcat
- SpringBoot异常处理回滚事务详解(自动回滚、手动回滚、部分回滚)(事务失效)
- [SpringBoot系列]SSMP整合小项目