Mybatis常用注解说明

@Insert : 插入sql , 和xml insert sql语法完全一样。
@Select : 查询sql, 和xml select sql语法完全一样。
@Update : 更新sql, 和xml update sql语法完全一样。
@Delete : 删除sql, 和xml delete sql语法完全一样。
@Param : 用于传递多个参数到xml。
@Results : 结果集合
@Result : 结果
@ResultMap:实现引用@Results定义的封装
@One:实现一对一结果集封装
@Many:实现一对多结果集封装
@SelectProvider:实现动态SQL映射
@CacheNamespace:实现注解二级缓存的使用

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot 是一个基于 Spring 框架的快速开发框架,而 MyBatis-Plus 则是 MyBatis 的增强工具,提供了很多方便的查询和操作数据库的 API。下面是 Spring Boot 加 MyBatis-Plus 的使用说明: 1. 配置 MyBatis-Plus 在 pom.xml 文件中添加 MyBatis-Plus 的依赖: ``` <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.3.3</version> </dependency> ``` 在 application.yml 文件中添加数据库连接信息和 MyBatis-Plus 的配置: ``` spring: datasource: url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8 username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver mybatis-plus: mapper-locations: classpath:mapper/*.xml global-config: db-config: id-type: auto field-strategy: not_empty table-prefix: mp_ ``` 2. 创建实体类和 Mapper 接口 创建实体类和对应的 Mapper 接口,使用 @TableName 注解指定表名,@TableField 注解指定字段名。 ``` @Data @TableName("user") public class User { @TableId(type=IdType.AUTO) private Long id; @TableField("username") private String username; @TableField("password") private String password; } @Mapper public interface UserMapper extends BaseMapper<User> { } ``` 3. 使用 MyBatis-Plus 的 API 进行数据库操作 使用 MyBatis-Plus 的 API 进行数据库操作非常方便,比如查询所有用户: ``` @Autowired private UserMapper userMapper; public List<User> getAllUsers() { return userMapper.selectList(null); } ``` 其他常用的 API 包括:insert、updateById、deleteById、selectById 等。 以上就是 Spring Boot 加 MyBatis-Plus 的简单使用说明,更多详细的使用方法可以参考 MyBatis-Plus 的官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值