当前位置: 首页 > news >正文

封装动态SQL的插件

最近根据公司的业务需要封装了一个简单的动态SQL的插件,要求是允许用户在页面添加SQL的where条件,然后开发者只需要给某个接口写查询对应的表,参数全部由插件进行拼接完成。下面是最终实现:
开发人员只需要在接口写上下面的查询SQL,然后用户可以在页面上添加需要关联的字段,由于没有写页面所里这里直接数据库里面配置

SELECT * FROM user;

添加表字段

insert into t_table_field (id, table_name, table_alis, table_filed, table_filed_type, create_time, update_time, deleted)
values  (1, 'user', 'u', 'create_time', 'datetime', '2023-07-18 13:55:02', '2023-07-18 13:55:02', 0);

添加增强字段

insert into t_data_controller (id, creator, func_tag, left_field_id, expression, right_field_value, sort_id, relation_expression, create_time, update_time, deleted, group_id)
values  (1, 123, 'user/query', 1, '>', '${query.startTime}', 0, 'or', '2023-07-18 14:23:16', '2023-07-19 11:01:00', 0, 1),(2, 123, 'user/query', 1, '<=', '${query.endTime}', 1, 'and', '2023-07-18 14:39:21', '2023-07-19 11:01:00', 0, 1);

测试代码

@Test
public void test_page() {CustomerQuery customerQuery = new CustomerQuery().setFuncTag("customer/query").setStartTime(time).setEndTime(endTime);IPage<Customer> customerPage = this.customerDao.selectPageDynamic(Condition.getPage(customerQuery), customerQuery);
}

最终代码拼接出来的样子

SELECT * FROM customer WHERE (create_time > 'Wed Apr 13 10:16:11 CST 2022' AND create_time <= 'Thu Apr 14 11:02:46 CST 2022') ORDER BY create_time DESC LIMIT ?

目前插件封装的比较仓促时间也不够,所以封装的比较简单,现在可以实现子查询的参数映射、where条件的拼接,表达式分组的实现,具体有兴趣的可以看看源码。
在这里插入图片描述
代码仓库

https://gitee.com/haijun1998/spring-boot-component-starter.git

http://www.lryc.cn/news/106864.html

相关文章:

  • C# Microsoft消息队列服务器的使用 MSMQ
  • Kafka3.0.0版本——生产者如何提高吞吐量
  • js精度丢失的问题
  • C++ 编译预处理
  • 备战秋招 | 笔试强化22
  • LeetCode ACM模式——哈希表篇(二)
  • hadoop 3.1.3集群搭建 ubuntu20
  • 备忘录模式——撤销功能的实现
  • Golang 函数参数的传递方式 值传递,引用传递
  • K8s影响Pod调度和Deployment
  • 透明代理和不透明代理
  • 1424. 对角线遍历 II;2369. 检查数组是否存在有效划分;1129. 颜色交替的最短路径
  • 【漏洞复现】Metabase 远程命令执行漏洞(CVE-2023-38646)
  • Linux 9的repo for OVS build
  • DOCTYPE 是什么作用?
  • KubeSphere 3.4.0 发布:支持 K8s v1.26
  • 自然语言文本分类模型代码
  • Prometheus实现系统监控报警邮件
  • could not import go.etcd.io/etcd/clientv3-go
  • MySQL的行锁、表锁触发
  • mysql-入门笔记-3
  • 3分钟创建超实用的中小学新生录取查询系统,现在可以实现了
  • Redis 变慢了 解决方案
  • 远程仓库的操作
  • 一个监控系统的典型架构
  • 让GPT人工智能变身常用工具-中
  • HCIP中期实验
  • 《向量数据库指南》——向量数据库Milvus Cloud、Pinecone、Vespa、Weaviate、Vald、GSI 、 Qdrant选哪个?
  • python与深度学习(十一):CNN和猫狗大战
  • 经典CNN(三):DenseNet算法实战与解析