diff --git a/spring-boot-demo-orm-mybatis-plus/README.md b/spring-boot-demo-orm-mybatis-plus/README.md index 3bfc74d..658fd20 100644 --- a/spring-boot-demo-orm-mybatis-plus/README.md +++ b/spring-boot-demo-orm-mybatis-plus/README.md @@ -1,6 +1,8 @@ # spring-boot-demo-orm-mybatis-plus > 此 demo 演示了 Spring Boot 如何集成 mybatis-plus,简化Mybatis开发,带给你难以置信的开发体验。 +> +> - 2019-09-14 新增:ActiveRecord 模式操作 ## pom.xml @@ -420,6 +422,121 @@ public class UserServiceTest extends SpringBootDemoOrmMybatisPlusApplicationTest } ``` +## 2019-09-14新增 + +### ActiveRecord 模式 + +- Role.java + +```java +/** + *
+ * 角色实体类 + *
+ * + * @author yangkai.shen + * @date Created in 2019/9/16 14:04 + */ +@Data +@TableName("orm_role") +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = true) +public class Role extends Model+ * RoleMapper + *
+ * + * @author yangkai.shen + * @date Created in 2019/9/16 14:06 + */ +public interface RoleMapper extends BaseMapper+ * Role + *
+ * + * @author yangkai.shen + * @date Created in 2019/9/16 14:19 + */ +@Slf4j +public class ActiveRecordTest extends SpringBootDemoOrmMybatisPlusApplicationTests { + /** + * 测试 ActiveRecord 插入数据 + */ + @Test + public void testActiveRecordInsert() { + Role role = new Role(); + role.setName("VIP"); + Assert.assertTrue(role.insert()); + // 成功直接拿会写的 ID + log.debug("【role】= {}", role); + } + + /** + * 测试 ActiveRecord 更新数据 + */ + @Test + public void testActiveRecordUpdate() { + Assert.assertTrue(new Role().setId(1L).setName("管理员-1").updateById()); + Assert.assertTrue(new Role().update(new UpdateWrapper