Easyquery
Make query easier for Java web service.
Install / Use
/learn @wwtg99/EasyqueryREADME
Easyquery
Make query easier for Java web service.
<h4 align="right"><strong>English</strong> | <a href="./README_zh.md">简体中文</a></h4> <p align="center"> <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license"> <img src="https://img.shields.io/badge/JDK-17+-green.svg" alt="jdk"> </p>Introduction
Easyquery can be used to quickly and easily build query requests, such as filtering, searching, and sorting, by defining query objects and automatically building query SQL, eliminating the need to manually splice SQL or assemble query code.
For example, let's say we are using MybatisPlus, our query request interface queries the table job, the entity object is shown below, and now we want to add the fields name, type for filtering, and created_time for sorting. Generally we can write it like this:
// Entity job.java
@Data
@TableName("job")
public class Job {
@TableId(type = IdType.AUTO)
private String id;
private OffsetDateTime createdTime;
private OffsetDateTime updatedTime;
private String name;
private String type;
private String remark;
}
// build query in JobServiceImpl.java, JobMapper and IJobService are omitted.
@Service
public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements IJobService {
public List<Job> listJob(String name, String type, boolean createdTimeAsc) {
QueryWrapper<Job> wrapper = new QueryWrapper<>();
if (Objects.nonNull(name)) {
wrapper.eq("name", name);
}
if (Objects.nonNull(type)) {
wrapper.eq("type", type);
}
wrapper.orderBy(true, createdTimeAsc, "created_time");
return list(wrapper);
}
}
While Easyquery can simplify the above steps, a series of query construction statement is simplified to a DTO object configuration, through the configuration of the object can be transformed to QueryWrapper, service can be called directly.
// DTO Object
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class JobDTO {
@QueryFilter
private String name;
@QueryFilter
private String type;
@QuerySorter
private Boolean createdTime;
}
// called in controller class(or in service class)
@PostMapping("/listJob")
public ResponseEntity<?> listJob(@RequestBody JobDTO dto) {
MyBatisPlusQueryWrapper<Job> wrapper = new MyBatisPlusQueryWrapper<>(extractorHolder);
QueryWrapper<Job> queryWrapper = wrapper.build(dto);
List<Job> data = jobService.list(queryWrapper);
return ResponseEntity.ok(data);
}
Easyquery can be configured according to the DTO object and the request body is automatically transformed to the QueryWrapper , eliminating the need to manually build the tedious code.
Easyquery also supports a variety of filtering operators (greater than, less than, contains, non-empty , etc.), multi-field search , combined sorting and other functions.
Easyquery core library based on JDK 17 +, no other dependencies, based on the user's Mybatis enhancement framework (currently supports MybatisPlus and MybatisFlex).
Installation
Please import the Mybatis-Plus or Mybatis-Flex dependency by yourself first and import the corresponding dependency.
For Mybatis-Plus
Maven
<dependency>
<groupId>io.github.wwtg99</groupId>
<artifactId>easyquery-mybatis-plus</artifactId>
<version>1.1.1</version>
</dependency>
Gradle
implementation 'io.github.wwtg99:easyquery-mybatis-plus:1.1.1'
For Mybatis-Flex
Maven
<dependency>
<groupId>io.github.wwtg99</groupId>
<artifactId>easyquery-mybatis-flex</artifactId>
<version>1.1.1</version>
</dependency>
Gradle
implementation 'io.github.wwtg99:easyquery-mybatis-flex:1.1.1'
Usage
Demo
Documents
Documents generated by DeepWiki.
Tests
Depends on JUnit 5, please use Maven run the unit tests.
mvn test
Related Skills
node-connect
346.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
