MyBatis Articles
5 articles about MyBatis. Explore Spring Boot implementation, design, and operations across related topics.
-
Dynamic SQL in Spring Boot + MyBatis: How to Write where, set, trim, choose, bind, and foreach, and How to Fix "Leading AND Left Behind", "Trailing Comma", and "Empty IN Clause Crashes"
A walkthrough of Spring Boot + MyBatis dynamic SQL tags (where/set/trim/choose/bind/foreach), showing the XML you write side by side with the SQL actually issued. Covers a search Mapper that doesn't break even when every condition is empty, partial updates that never leave a trailing comma, and defensive patterns so foreach doesn't fail when given an empty list or null, organized as fixes by error type.
-
How to Map One-to-Many and Many-to-One Join Results with Spring Boot + MyBatis - resultMap association/collection and N+1 Countermeasures
Explains how to load parent-child table JOIN results into hierarchical DTOs with Spring Boot 3 + MyBatis. Covers resultMap association (many-to-one) and collection (one-to-many), avoiding column collisions with columnPrefix, a comparison of the number of SQL statements issued by nested select vs. nested resultMap (measured N+1), and the pitfall of mismatched row counts when combined with paging along with workarounds, with copy-paste-ready code in both XML and annotation styles.
-
How to Implement Pagination with Spring Boot + MyBatis - Choosing Between PageHelper, RowBounds, and Hand-Written LIMIT/OFFSET
Compares three approaches to paginating list APIs in Spring Boot + MyBatis (hand-written LIMIT/OFFSET, RowBounds, and PageHelper) in terms of generated SQL, count retrieval, sorting, and extra dependencies. Explains why RowBounds results in in-memory pagination, the thread-local pitfalls of PageHelper and its helperDialect setting, and how to convert to Spring Data's Pageable, all with ready-to-run code.
-
How to Use MyBatis with Spring Boot - An Implementation Guide to Mapper Definitions, Dynamic SQL, and Result Mapping
An implementation guide to integrating MyBatis into Spring Boot from scratch. It covers everything from adding the mybatis-spring-boot-starter dependency, defining Mappers using both annotation and XML notations, dynamic SQL with the if and foreach tags, mapping join results with resultMap, the safety of #{} vs ${}, and @Transactional integration—all explained with working code.
-
MyBatis vs JPA in Spring Boot - Selection Criteria and Combined Usage Patterns [With Comparison Table]
Wondering whether to choose MyBatis or JPA for your Spring Boot project? This article organizes SQL control flexibility, learning cost, performance, and maintainability in a comparison table, and explains practical decision flowcharts, the difference between #{} and ${}, and concrete configuration examples for using both together. Get all the decision criteria in one place.