From 70c97ada72d1473aea01d1334724ccde98d0564a Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Sat, 1 Jul 2023 22:59:25 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=B5=8B=E8=AF=95=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=AB=E5=90=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mybatisflex/test/entity/Inner.java | 54 +++++++++++++++ .../com/mybatisflex/test/entity/Outer.java | 62 +++++++++++++++++ .../mybatisflex/test/model/AccountVO2.java | 1 - .../src/main/resources/application.yml | 16 ++--- .../test/mapper/OuterMapperTest.java | 67 +++++++++++++++++++ 5 files changed, 191 insertions(+), 9 deletions(-) create mode 100644 mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Inner.java create mode 100644 mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Outer.java create mode 100644 mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/OuterMapperTest.java diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Inner.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Inner.java new file mode 100644 index 00000000..f6a7ba06 --- /dev/null +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Inner.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mybatisflex.test.entity; + +import com.mybatisflex.annotation.Table; + +/** + * @author 王帅 + * @since 2023-07-01 + */ +@Table("tb_inner") +public class Inner { + + private Integer id; + private String type; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Override + public String toString() { + return "Inner{" + + "id=" + id + + ", type='" + type + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Outer.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Outer.java new file mode 100644 index 00000000..547a56c7 --- /dev/null +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Outer.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mybatisflex.test.entity;
+
+import com.mybatisflex.annotation.As;
+import com.mybatisflex.annotation.Table;
+import com.mybatisflex.test.model.IdEntity;
+
+/**
+ * @author 王帅
+ * @since 2023-06-16
+ */
+@Table("tb_outer")
+public class Outer extends IdEntity
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mybatisflex.test.mapper;
+
+import com.mybatisflex.core.query.QueryWrapper;
+import com.mybatisflex.test.entity.Inner;
+import com.mybatisflex.test.entity.Outer;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import static com.mybatisflex.test.entity.table.InnerTableDef.INNER;
+import static com.mybatisflex.test.entity.table.OuterTableDef.OUTER;
+
+/**
+ * @author 王帅
+ * @since 2023-07-01
+ */
+@SpringBootTest
+class OuterMapperTest {
+
+ @Autowired
+ private OuterMapper outerMapper;
+
+ @Autowired
+ private InnerMapper innerMapper;
+
+ @Test
+ void testInsert() {
+ Outer outer = new Outer();
+ outer.setName("outer 01");
+ outerMapper.insertSelective(outer);
+
+ Inner inner = new Inner();
+ inner.setId(2);
+ inner.setType("inner type");
+ innerMapper.insertWithPk(inner);
+ }
+
+ @Test
+ void testSelect() {
+ QueryWrapper queryWrapper = QueryWrapper.create()
+ .select(OUTER.ID,
+ OUTER.NAME,
+ INNER.ID,
+ INNER.TYPE)
+ .from(OUTER.as("o"))
+ .leftJoin(INNER).as("i").on(INNER.ID.eq(2));
+ Outer outer = outerMapper.selectOneByQuery(queryWrapper);
+ System.out.println(outer);
+ }
+
+}
\ No newline at end of file