diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Entity04.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Entity04.java index e208b7b3..634eff13 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Entity04.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Entity04.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2025, Mybatis-Flex (fuhai999@gmail.com). + * Copyright (c) 2022-2024, 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. @@ -16,7 +16,11 @@ package com.mybatisflex.test; -import com.mybatisflex.annotation.*; +import com.mybatisflex.annotation.Column; +import com.mybatisflex.annotation.ColumnMask; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; +import com.mybatisflex.annotation.Table; import com.mybatisflex.core.handler.Fastjson2TypeHandler; import com.mybatisflex.core.mask.Masks; @@ -42,7 +46,7 @@ public class Entity04 extends BaseAccount implements Serializable { @NotBlank private Date birthday; - @Column(typeHandler = Fastjson2TypeHandler.class, isLarge = true) + @Column(typeHandler = Fastjson2TypeHandler.class) private Map options; @Column(isLogicDelete = true) diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/QueryWrapperTest.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/QueryWrapperTest.java index 7855bb4d..e531aa96 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/QueryWrapperTest.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/QueryWrapperTest.java @@ -1,48 +1,68 @@ +/* + * Copyright (c) 2022-2024, 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; import com.mybatisflex.core.MybatisFlexBootstrap; import com.mybatisflex.core.audit.AuditManager; import com.mybatisflex.core.audit.ConsoleMessageCollector; -import com.mybatisflex.core.audit.MessageCollector; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.mapper.Entity04Mapper; -import com.mybatisflex.test.table.Entity04TableDef; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import javax.sql.DataSource; +import java.util.Collections; import java.util.List; public class QueryWrapperTest { public static void main(String[] args) { - DataSource dataSource = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).addScript("schema04.sql") - .addScript("data04.sql").build(); + DataSource dataSource = new EmbeddedDatabaseBuilder() + .setType(EmbeddedDatabaseType.H2) + .addScript("schema04.sql") + .addScript("data04.sql") + .build(); - MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance().setDataSource(dataSource) - .addMapper(Entity04Mapper.class).start(); + MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() + .setDataSource(dataSource) + .addMapper(Entity04Mapper.class) + .start(); - //开启审计功能 + // 开启审计功能 AuditManager.setAuditEnable(true); - //设置 SQL 审计收集器 - MessageCollector collector = new ConsoleMessageCollector(); - AuditManager.setMessageCollector(collector); + // 设置 SQL 审计收集器 + AuditManager.setMessageCollector(new ConsoleMessageCollector()); Entity04Mapper mapper = bootstrap.getMapper(Entity04Mapper.class); Entity04 entity04 = new Entity04(); - entity04.setId("1"); + entity04.setId("3"); entity04.setAge(200); + entity04.setOptions(Collections.singletonMap("key", "value")); mapper.insertSelective(entity04); - System.out.println("--------------------selectListByQuery"); + // 调用 Fastjson2TypeHandler 处理 options 属性拼接到查询语句中 QueryWrapper queryWrapper = QueryWrapper.create(entity04); List entity04s = mapper.selectListByQuery(queryWrapper); - System.out.println(entity04s); - - System.out.println(Entity04TableDef.ENTITY04.AGE); + System.out.println(entity04); + System.out.println(entity04s.get(0)); + System.out.println(entity04.toString().equals(entity04s.get(0).toString())); } }