Merge remote-tracking branch 'origin/master'

This commit is contained in:
wangyu 2023-02-07 10:04:59 +08:00
commit b9a34446ae
6 changed files with 70 additions and 4 deletions

View File

@ -79,6 +79,24 @@ public class FluentSqlConfig {
}
```
## 单表查询
单表查询可以省略结果映射,程序自动使用主表实体进行自动映射
```java
class Test {
public static void main(String[] args) {
// 单表查询所有字段
List<SaasTenant> tenants = select().from(SaasTenant.class).list();
// 单表查询指定字段,条件 年龄小于50
List<SaasTenant> points = select(SaasTenant::getId, SaasTenant::getName).from(SaasTenant.class)
.matching(where(SaasTenant::getAge).lt(50))
.list();
}
}
```
## 对比直接书写SQL
本小组件主要解决的是sql的书写问题旨在用更加优雅的方式实现sql并且不用再担心数据库方言SQL Dialect

View File

@ -7,6 +7,7 @@ import group.flyfish.fluent.operations.JdbcTemplateFluentSQLOperations;
import group.flyfish.framework.cases.FluentSqlTestCase;
import group.flyfish.framework.cases.JdbcTestCase;
import group.flyfish.framework.cases.MybatisTestCase;
import group.flyfish.framework.cases.SingleTableTestCase;
import org.junit.Test;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcOperations;
@ -36,7 +37,7 @@ public class FluentJdbcTest {
new Driver(),
"jdbc:mysql://127.0.0.1:3306/epi_project?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=Asia/Shanghai",
"root",
"Unicom#2018"
"oI3WtMO8h%mSYARp"
);
// 准备待测试用例
List<TestCase<?>> cases = Arrays.asList(
@ -46,6 +47,8 @@ public class FluentJdbcTest {
);
// 执行测试
cases.forEach(TestCase::test);
// 单表测试
new SingleTableTestCase().test();
}
/**

View File

@ -33,7 +33,7 @@ public class FluentSqlTestCase extends AbstractTestCase<List<TenantContext>> {
// 基于构造器自动绑定注册在实际应用中使用@Bean声明即可可参考下面的demo
new JdbcTemplateFluentSQLOperations(new JdbcTemplate(dataSource));
// 启用调试
FluentSqlDebugger.enable();
// FluentSqlDebugger.enable();
}
/**

View File

@ -1,6 +1,7 @@
package group.flyfish.framework.cases;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import group.flyfish.fluent.utils.data.ObjectMappers;
import group.flyfish.framework.TestCase;
import group.flyfish.framework.entity.SaasQuota;
import group.flyfish.framework.entity.SaasTenant;
@ -40,6 +41,7 @@ public class MybatisTestCase extends AbstractTestCase<List<TenantContext>> {
Configuration configuration = new Configuration(environment);
configuration.addMapper(TenantContextMapper.class);
TypeHandlerRegistry registry = configuration.getTypeHandlerRegistry();
JacksonTypeHandler.setObjectMapper(ObjectMappers.shared());
registry.register(SaasTenant.DataSourceConfig.class, JacksonTypeHandler.class);
registry.register(SaasQuota.class, JacksonTypeHandler.class);
registry.register(SaasTenant.StorageConfig.class, JacksonTypeHandler.class);

View File

@ -0,0 +1,43 @@
package group.flyfish.framework.cases;
import group.flyfish.framework.TestCase;
import group.flyfish.framework.entity.SaasTenant;
import java.util.List;
import static group.flyfish.fluent.chain.SQL.select;
/**
* 单表测试用例
*
* @author wangyu
*/
@TestCase.Name("单表查询测试")
public class SingleTableTestCase extends AbstractTestCase<List<SaasTenant>> {
public SingleTableTestCase() {
super(null);
}
/**
* 初始化
*
* @throws Exception 异常
*/
@Override
public void initialize() throws Exception {
}
/**
* 测试运行逻辑
*
* @return 运行结果
* @throws Exception 异常
*/
@Override
public List<SaasTenant> run() throws Exception {
// 单表查询
return select().from(SaasTenant.class).list();
}
}

View File

@ -10,7 +10,7 @@
<result column="storage" property="storage" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" />
<result column="status" property="status" />
<result column="enable" property="enable" />
<result column="quotaConfig" property="quota" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" />
<result column="quota" property="quota" jdbcType="LONGVARCHAR" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" />
<result column="orderTime" property="orderTime" />
<result column="expireTime" property="expireTime" />
<result column="orderType" property="orderType" />
@ -24,7 +24,7 @@
t1.`storage` as `storage`,
t1.`status` as `status`,
t1.`enable` as `enable`,
t2.`quota_config` as `quotaConfig`,
t2.`quota_config` as `quota`,
t2.`order_time` as `orderTime`,
t2.`expire_time` as `expireTime`,
t2.`order_type` as `orderType`