Search in sources :

Example 1 with Student

use of com.baomidou.samples.execution.entity.Student in project mybatis-plus-samples by baomidou.

the class ExecutionTest method test.

@Test
void test() {
    studentMapper.selectList(new QueryWrapper<>());
    studentMapper.deleteById(1L);
    Student student = new Student();
    student.setName("test_update");
    studentMapper.insert(new Student(1L, "test", 12));
    studentMapper.update(student, new QueryWrapper<Student>().eq("id", 1L));
    try {
        studentMapper.update(new Student(), new QueryWrapper<>());
    } catch (MyBatisSystemException e) {
    }
    try {
        studentMapper.delete(new QueryWrapper<>());
    } catch (MyBatisSystemException e) {
        System.err.println("执行了全表删除拦截,删除无效!异常:" + e.getMessage());
    }
    Assertions.assertTrue(CollectionUtils.isNotEmpty(studentMapper.selectList(new QueryWrapper<>())), "数据都被删掉了.(┬_┬)");
}
Also used : MyBatisSystemException(org.mybatis.spring.MyBatisSystemException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Student(com.baomidou.samples.execution.entity.Student) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Student

use of com.baomidou.samples.execution.entity.Student in project tutorials-java by Artister.

the class ExecutionTest method test.

@Test
public void test() {
    studentMapper.selectList(new QueryWrapper<>());
    studentMapper.deleteById(1L);
    Student student = new Student();
    student.setName("test_update");
    studentMapper.insert(new Student(1L, "test", 12));
    studentMapper.update(student, new QueryWrapper<Student>().eq("id", 1L));
    try {
        studentMapper.update(new Student(), new QueryWrapper<>());
    } catch (MyBatisSystemException e) {
    }
    try {
        studentMapper.delete(new QueryWrapper<>());
    } catch (MyBatisSystemException e) {
    }
    Assert.notEmpty(studentMapper.selectList(new QueryWrapper<>()), "数据都被删掉了.(┬_┬)");
}
Also used : MyBatisSystemException(org.mybatis.spring.MyBatisSystemException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Student(com.baomidou.samples.execution.entity.Student) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)2 Student (com.baomidou.samples.execution.entity.Student)2 MyBatisSystemException (org.mybatis.spring.MyBatisSystemException)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1