![]()
腾讯 APIJSON 是一种专为 API 而生的 JSON 网络传输协议 以及 基于这套协议实现的 ORM 库。
为各种增删改查提供了完全自动化的万能 API,零代码实时满足千变万化的各种新增和变更需求。
能大幅降低开发和沟通成本,简化开发流程,缩短开发周期。适合中小型前后端分离的项目。
自 2016 年开源 7 年来发展迅速,目前 16K+ Star 位居 400W Java 开源项目前 100。
国内 腾讯、华为、阿里巴巴、字节跳动、美团、拼多多、百度、京东、网易、快手、圆通 等 和
国外 Google, Apple, Microsoft, Amazon, Tesla, Meta(FB), Paypal 等数百个知名大厂员工 Star,
也有 腾讯、华为、字节跳动、Microsoft、Zoom、知乎 等 工程师/专家/架构师 提了 PR/Issue,
还被 腾讯、华为、百度、SHEIN、快手、中兴、传音、圆通、美图 等各大知名厂商用于各类项目。
![]()
![]()
apijson-query-spring-boot-starter
1.0.1-1.0.2 更新内容:
- 返回结果使用驼峰规则转换;
- 修复list转为字符串问题;
- 修复查询空值报错问题;
插件介绍
一个快速构建apijson查询条件的插件
通常我们在数仓或者其他场景中会使用apijson提供通用接口,这时候会有其他应用需要调用apijson接口,虽然apijson提供通用的json格式参数调用, 但是由于apijson单独实现一套语法规则,需要学习成本,此插件的目的就是像使用mybatis plus构建sql查询参数一样,去构建apijson查询条件,无需任何apijson语法学习,即可完成通用查询请求。
查询构建使用示例
- 基于ApiJsonQueryLambdaWrapper构建查询
public class Test {
public void testQuery() {
ApiJsonQueryLambdaWrapper queryWrapper = ApiJsonQueryWrappers.lambdaQuery()
.setSchema("模式名")
.setTableName("表名")
.setBiSigns("业务标识")
.select("查询列")
.eq("条件判断", "条件列", "条件值")
// ...
;
}
}
- 基于ApiJsonQueryStringWrapper构建查询
public class Test {
public void testQuery() {
ApiJsonQueryStringWrapper queryWrapper = ApiJsonQueryWrappers.query()
.setSchema("模式名")
.setTableName("表名")
.setBiSigns("业务标识")
.select("查询列")
.eq("条件判断", "条件列", "条件值")
//...
;
}
}
- 基于ApiJsonQueryMapWrapper构建查询
public class Test {
public void testQuery() {
Map<String, Object> param = new HashMap<>();
//apijson原生语法
param.put("键", "值");
//...
ApiJsonQueryMapWrapper queryWrapper = ApiJsonQueryWrappers.mapQuery()
.setQueryParam(param);
}
}
方法调用使用示例
提供ApiJsonQueryTemplate模板方法
public class Test {
@Autowired
private ApiJsonQueryTemplate apiJsonQueryTemplate;
public void testGetOne() {
User user = apiJsonQueryTemplate.getOne(queryWrapper, User.class);
}
}
public class Test {
@Autowired
private ApiJsonQueryTemplate apiJsonQueryTemplate;
public void testCount() {
Long count = apiJsonQueryTemplate.count(queryWrapper);
}
}
public class Test {
@Autowired
private ApiJsonQueryTemplate apiJsonQueryTemplate;
public void testGetList() {
List<User> userList = apiJsonQueryTemplate.getList(queryWrapper, User.class);
}
}
- 查询分页列表 getPageList(查询条件,当前页,页大小,转换类型)
public class Test {
@Autowired
private ApiJsonQueryTemplate apiJsonQueryTemplate;
public void testGetPageList() {
ApiJsonPageInfo<User> userPageList = apiJsonQueryTemplate.getPageList(queryWrapper, 1, 10, User.class);
}
}
扩展查询数据源示例
提供默认基于http形式的apijson数据源查询方法,如果不满足需求,可继承DwQueryDao接口,实现getData方法,然后再装配Bean
public class AutoConfiguration {
@Resource
private ApiJsonQueryProperties apiJsonQueryProperties;
@Bean
public ApiJsonQueryTemplate apiJsonQueryTemplate() {
log.debug("加载自定义查询数据源实现....");
ApiJsonQueryTemplate apiJsonQueryTemplate = new ApiJsonQueryTemplate();
//自定义查询数据源
ApiJsonQueryDao customQuery = new CustomQueryImpl(apiJsonQueryProperties);
apiJsonQueryTemplate.setDao(customQuery);
return apiJsonQueryTemplate;
}
}
注解说明
@ApiJsonTableName(
value = "表名",
schema = "模式名",
biSigns = "业务标识",
desc = "描述"
)
public class TestDO{
}
//注解设置完成后,只需要在构建查询条件时 setTableName(TestDO.class)即可
@ApiJsonTableName(
value = "表名",
schema = "模式名",
biSigns = "业务标识",
desc = "描述"
)
public class TestDO {
//将name映射为name2查询
@ApiJsonTableField(value = "name2")
private String name;
//忽略该字段查询
@ApiJsonTableField(exist = false)
private String value;
}
//注解设置完成后,只需要在构建查询条件时 setTableName(TestDO.class)即可
创作不易,打开以下链接右上角点亮 ⭐️ 来支持/收藏下吧~
https://gitee.com/mingbaobaba/apijson-query-spring-boot-starter