伊春网站优化,wordpress首页等待画面,深圳南山区网站建设公司,南通微信网站开发最近根据公司的业务需要封装了一个简单的动态SQL的插件#xff0c;要求是允许用户在页面添加SQL的where条件#xff0c;然后开发者只需要给某个接口写查询对应的表#xff0c;参数全部由插件进行拼接完成。下面是最终实现#xff1a; 开发人员只需要在接口写上下面的查询SQ…最近根据公司的业务需要封装了一个简单的动态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);IPageCustomer 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