随笔分类 - MyBatisPlus
添加和修改
摘要:MyBatisPlus实现添加操作 @Test public void addUser() { User user = new User(); user.setName("leavescai7"); user.setAge(26); user.setEmail("376650839@qq.com")
阅读全文
删除
摘要://第一步 添加属性和注解 @TableLogic private Integer deleted //第二步 配置逻辑删除插件 @Bean public ISqlInjector sqlInjector() { return new LogicSqlInjector(); } applicatio
阅读全文
查询
摘要:MyBatisPlus简单查询 1、根据id查询 //根据id查询数据 User user = userMapper.selectById(9001); 2、多个id批量查询 方法:selectBatchIds(Collection<? extends Serializable> collectio
阅读全文
乐观锁
摘要:乐观锁的具体实现 原理:是通过乐观锁版本号实现的(添加字段version) //在表中添加字段 version version int 11 //在实体类版本号属性添加注解 @Version@TableField(fill= FieldFill.INSERT)private Integer vers
阅读全文
自动填充
摘要:开发中常用: 表中: create_time 、update_time 使用MyBatisPlus方式实现数据添加,无需 set 到对象里面值 //传统 set 方式 user.setCreateTime(new Date()); user.setUpdateTime(new Date()); My
阅读全文
主键策略
摘要:方式一: 自动增长 AUTO INCREMENT 方式二: UUID 每次生成随机唯一的值 缺点:排序不方便 方式三: redis实现 方式三: MyBatisPlus自带策略 snokflake算法 @TableId(type = IdType.AUTO) private Long id; AUT
阅读全文
浙公网安备 33010602011771号