Databases 8 min read

How Bean Searcher Lets You Build Complex Multi‑Table Queries with a Single Line of Code

Bean Searcher is an open‑source Java library that dramatically simplifies backend list retrieval by offering a high‑performance search engine with built‑in multi‑table joins, pagination, sorting, field selection and aggregation, allowing developers to implement complex queries in just one line of code.

Java Backend Technology
Java Backend Technology
Java Backend Technology
How Bean Searcher Lets You Build Complex Multi‑Table Queries with a Single Line of Code

Project Overview

Bean Searcher is an open‑source Java library that provides a condition‑search engine up to 100 times faster than MyBatis, with native support for multi‑table joins, pagination, arbitrary field sorting, field selection and aggregation, all achievable with a single line of code.

Open‑Source License

Apache‑2.0

Key Features

Entity multi‑table mapping

Dynamic field operators

Group aggregation queries

Sub‑queries for SELECT, WHERE, FROM

Embedded entity parameters

Field converters

SQL interceptors

Database dialect extensions

Multiple and dynamic data sources

Default and custom annotations

Extensible field operators

Rapid Development

Using Bean Searcher can dramatically reduce development time for complex list‑search APIs.

Typical Use Case

A backend needs to expose a search endpoint with pagination, sorting, filtering and aggregation. Traditional ORM solutions require extensive code, whereas Bean Searcher accomplishes this with a single method call.

@SearchBean(tables="user u, role r", joinCond="u.role_id = r.id", autoMapTo="u")
public class User {
    private long id;
    private String username;
    private int status;
    private int age;
    private String gender;
    private Date joinDate;
    private int roleId;
    @DbField("r.name")
    private String roleName;
    // getters and setters
}
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private BeanSearcher beanSearcher;

    @GetMapping("/index")
    public SearchResult<User> index(HttpServletRequest request) {
        // only one line of code
        return beanSearcher.search(User.class, MapUtils.flat(request.getParameterMap()), new String[]{"age"});
    }
}

This single line implements multi‑table join, pagination, combined filters, arbitrary field sorting and field statistics.

Parameter Builder Example

Map<String, Object> params = MapUtils.builder()
    .selectExclude(User::getJoinDate) // exclude joinDate
    .field(User::getStatus, 1) // status = 1
    .field(User::getName, "Jack").ic() // name = 'Jack' (case ignored)
    .field(User::getAge, 20, 30).op(Opetator.Between) // age between 20 and 30
    .orderBy(User::getAge, "asc") // order by age asc
    .page(0, 15) // page 0, 15 items per page
    .build();
List<User> users = beanSearcher.searchList(User.class, params);

Integration

Bean Searcher can be integrated with any Java web framework such as Spring Boot, Spring MVC, Grails or JFinal. For Spring Boot, add the starter dependency:

implementation 'com.ejlchina:bean-searcher-boot-starter:3.6.0'

Then inject the searcher:

@Autowired
private BeanSearcher beanSearcher;

Extensibility

The library is interface‑driven, allowing custom extensions for field operators, field converters, annotation mapping, parameter resolvers and database dialects.

Source Code

Git repositories:

Gitee: https://gitee.com/ejlchina-zhxu/bean-searcher

GitHub: https://github.com/ejlchina/bean-searcher

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

javadatabaseORMSearchBeanSearcher
Java Backend Technology
Written by

Java Backend Technology

Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.