Comparing MyBatis‑Plus and Bean Searcher: Core Differences, Advanced Queries, and Practical Use Cases
This article compares MyBatis‑Plus and Bean Searcher, detailing their basic differences, dynamic query capabilities, logical grouping, multi‑table joins, performance benchmarks, supported databases, and recommended usage scenarios, while providing extensive code examples and best‑practice recommendations for backend developers.
Bean Searcher claims to handle any complex query with a single line of code, while MyBatis‑Plus offers similar dynamic query features; this article examines their differences.
Difference One (Basic)
MyBatis‑Plus depends on MyBatis and provides full CRUD, whereas Bean Searcher is ORM‑agnostic and focuses solely on advanced queries. Only projects using MyBatis can use MyBatis‑Plus; Bean Searcher works with any ORM or standalone.
MyBatis‑Plus requires an entity class and a Mapper interface; Bean Searcher only needs the entity class.
Difference Two (Advanced Query)
MyBatis‑Plus uses static field operators (e.g., = , > , like ), while Bean Searcher supports dynamic operators specified by request parameters.
Example entity:
public class User {
private long id;
private String name;
private int age;
// getters & setters omitted
}1) MyBatis‑Plus query
Dependency:
implementation 'com.baomidou:mybatis-plus-boot-starter:3.5.2'Mapper interface:
public interface UserMapper extends BaseMapper
{}Controller method:
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserMapper userMapper;
@GetMapping("/mp")
public List
mp(User user) {
return userMapper.selectList(new QueryWrapper<>(user));
}
}This supports only equality conditions; to query age > 20 you must add a custom annotation, which then limits the field to that operator.
2) Bean Searcher query
Dependency:
implementation 'cn.zhxu:bean-searcher-boot-starter:4.1.2'Controller method (no Mapper needed):
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private BeanSearcher beanSearcher;
@GetMapping("/bs")
public List
bs(@RequestParam Map
params) {
return beanSearcher.searchList(User.class, params);
}
}Bean Searcher allows many operator variations via parameters such as name‑op=ct (contains) or age‑op=gt (greater than), and supports case‑insensitive matching.
Difference Three (Logical Grouping)
Both default to AND logic, but Bean Searcher can group conditions using prefixes (e.g., a. , b. ) and a gexpr expression to combine groups with OR.
Example request: GET /user/bs?a.name=Jack&a.age=20&b.age=30&gexpr=a|b (URL‑encoded as a%7Cb ).
Difference Four (Multi‑Table Join)
MyBatis‑Plus dynamic queries are limited to single tables, while Bean Searcher can query across multiple tables using a @SearchBean annotation that defines tables, join conditions, and field mappings.
Example VO:
@SearchBean(
tables = "order o, shop s, user u",
where = "o.shop_id = s.id and o.buyer_id = u.id",
autoMapTo = "o"
)
public class OrderVO {
private long id; // o.id
private String orderNo; // o.order_no
private long amount; // o.amount
@DbField("s.name")
private String shop; // s.name
@DbField("u.name")
private String buyer; // u.name
// getters & setters omitted
}Controller uses the same one‑line search call.
Difference Five (Usage Scenarios)
Use MyBatis‑Plus for transactional operations; use Bean Searcher for read‑only, complex retrieval interfaces such as list pages, especially when advanced filtering, sorting, or multi‑table joins are required.
Common Questions
Security: Bean Searcher is read‑only and ignores unknown parameters, preventing SQL injection.
Performance: Benchmarks on H2 show Bean Searcher outperforms Spring Data JDBC (5‑10×), Spring Data JPA (2‑3×), native MyBatis (1‑2×), and MyBatis‑Plus (2‑5×).
Supported Databases: Any SQL‑compatible DB; built‑in dialects for MySQL‑style, PostgreSQL, Oracle, and SQL Server pagination.
Conclusion
MyBatis‑Plus and Bean Searcher serve different domains: MyBatis‑Plus excels in transactional CRUD, while Bean Searcher shines in advanced, dynamic, and multi‑table read queries, allowing developers to write concise code and return VO objects directly to the frontend.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.