miemie 4 năm trước cách đây
mục cha
commit
917d688542

+ 18 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/rewrite/Entity.java

@@ -0,0 +1,18 @@
+package com.baomidou.mybatisplus.test.rewrite;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author miemie
+ * @since 2020-06-23
+ */
+@Data
+public class Entity implements Serializable {
+    private static final long serialVersionUID = 6962439201546719734L;
+
+    private Long id;
+
+    private String name;
+}

+ 10 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/rewrite/EntityMapper.java

@@ -0,0 +1,10 @@
+package com.baomidou.mybatisplus.test.rewrite;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * @author miemie
+ * @since 2020-06-23
+ */
+public interface EntityMapper extends BaseMapper<Entity> {
+}

+ 37 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/rewrite/RewriteTest.java

@@ -0,0 +1,37 @@
+package com.baomidou.mybatisplus.test.rewrite;
+
+import com.baomidou.mybatisplus.test.BaseDbTest;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * @author miemie
+ * @since 2020-06-23
+ */
+public class RewriteTest extends BaseDbTest<EntityMapper> {
+
+    @Test
+    void replace() {
+        doTest(i -> {
+            Entity entity = i.selectById(1);
+            assertThat(entity.getName()).isNull();
+        });
+    }
+
+    @Override
+    protected String tableDataSql() {
+        return "insert into entity(id,name) values(1,'1'),(2,'2');";
+    }
+
+    @Override
+    protected List<String> tableSql() {
+        return Arrays.asList("drop table if exists entity", "CREATE TABLE IF NOT EXISTS entity (" +
+            "id BIGINT NOT NULL," +
+            "name VARCHAR(30) NULL DEFAULT NULL," +
+            "PRIMARY KEY (id))");
+    }
+}

+ 10 - 0
mybatis-plus/src/test/resources/com/baomidou/mybatisplus/test/rewrite/entityMapper.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.baomidou.mybatisplus.test.rewrite.EntityMapper">
+
+    <select id="selectById" resultType="com.baomidou.mybatisplus.test.rewrite.Entity">
+        select id
+        from entity
+        where id = #{id}
+    </select>
+</mapper>