mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 09:08:24 +08:00
74 lines
2.3 KiB
Java
74 lines
2.3 KiB
Java
/*
|
||
* Copyright (c) 2022-2023, 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.row.Db;
|
||
import com.mybatisflex.core.row.Row;
|
||
import org.apache.ibatis.session.Configuration;
|
||
import org.junit.Assert;
|
||
import org.junit.BeforeClass;
|
||
import org.junit.Test;
|
||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||
|
||
import javax.sql.DataSource;
|
||
import java.util.List;
|
||
|
||
/**
|
||
* @author 王帅
|
||
* @since 2023-10-11
|
||
*/
|
||
public class DbTest {
|
||
|
||
@BeforeClass
|
||
public static void init() {
|
||
DataSource dataSource = new EmbeddedDatabaseBuilder()
|
||
.setType(EmbeddedDatabaseType.H2)
|
||
.addScript("schema.sql")
|
||
.addScript("data.sql")
|
||
.build();
|
||
|
||
MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance()
|
||
.setDataSource(dataSource)
|
||
.start();
|
||
|
||
/*
|
||
* 指定当结果集中值为 null 的时候是否调用映射对象的 setter(map 对象时为 put)方法,
|
||
* 这在依赖于 Map.keySet() 或 null 值进行初始化时比较有用。注意基本类型(int、boolean 等)
|
||
* 是不能设置成 null 的。
|
||
*/
|
||
Configuration configuration = bootstrap.getConfiguration();
|
||
configuration.setCallSettersOnNulls(true);
|
||
|
||
Db.updateBySql("update tb_account set options = null;");
|
||
}
|
||
|
||
@SuppressWarnings("all")
|
||
static String tb_account = "tb_account";
|
||
|
||
@Test
|
||
public void test01() {
|
||
List<Row> rows = Db.selectAll(tb_account);
|
||
|
||
rows.stream()
|
||
.map(row -> row.get("OPTIONS"))
|
||
.forEach(Assert::assertNull);
|
||
}
|
||
|
||
}
|