mybatisplus基本使用

1.根据id查询

User user = userMapper.selectById(id);

2.多个id

User user = userMapper.selectBatchIds(id1,id2,id3);

3.多条件查询

Map map = new HashMap();
map.put(name,"AA");
map.put(age,);
User user = userMapper.selectByMap(map);

4.分页查询

在这里插入图片描述

5.逻辑删除
在这里插入图片描述
在这里插入图片描述
6.条件查询
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MyBatisPlus 是 MyBatis 的增强工具,可以简化 MyBatis开发过程。使用 MyBatisPlus 可以省去很多繁琐的 SQL 操作,提高开发效率。下面是 MyBatisPlus 的使用步骤: 1. 引入 MyBatisPlus 的依赖 在项目的 pom.xml 文件中添加 MyBatisPlus 的依赖: ```xml <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.0.7.1</version> </dependency> ``` 2. 配置 MyBatisPlus 在项目的 application.properties 或 application.yml 文件中添加 MyBatisPlus 的配置: ```yaml mybatis-plus: mapper-locations: classpath:mapper/*.xml global-config: db-config: id-type: auto ``` 3. 创建实体类 创建与数据库表对应的实体类,并使用注解 @TableName 指定表名,@TableId 指定主键。 ```java @Data @TableName("user") public class User { @TableId(type = IdType.AUTO) private Long id; private String name; private Integer age; private String email; } ``` 4. 创建 Mapper 接口 创建继承 BaseMapper 的 Mapper 接口,BaseMapper 中已经封装了常用的 CRUD 操作。 ```java public interface UserMapper extends BaseMapper<User> { } ``` 5. 使用 MyBatisPlus 进行操作 使用 MyBatisPlus 提供的 API 进行数据库操作。 ```java @Autowired private UserMapper userMapper; public void addUser(User user) { userMapper.insert(user); } public User getUserById(Long id) { return userMapper.selectById(id); } public void updateUser(User user) { userMapper.updateById(user); } public void deleteUserById(Long id) { userMapper.deleteById(id); } ``` 以上就是使用 MyBatisPlus 的基本步骤,当然还有很多高级用法和扩展功能,可以根据具体需求进行学习和使用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值