mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 08:38:26 +08:00
test: 测试使用实体类构建 QueryWrapper 时。
This commit is contained in:
parent
0df1ea103b
commit
003d105e58
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2025, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* Copyright (c) 2022-2024, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* 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<String, Object> options;
|
||||
|
||||
@Column(isLogicDelete = true)
|
||||
|
||||
@ -1,48 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2024, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* 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<Entity04> 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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user