Dynamic SQL Articles
4 articles about Dynamic SQL. Explore Spring Boot implementation, design, and operations across related topics.
-
Spring Boot + MyBatis: How to Build Dynamic SQL with Java Code Only Using SqlProvider
For those tired of MyBatis XML dynamic SQL, this article explains how to build dynamic SQL using only Java code with @SelectProvider/@InsertProvider/@UpdateProvider. It covers implementation examples using SqlBuilder and string concatenation, passing multiple arguments, common pitfalls, and criteria for choosing between this approach and the XML method, all from a practical standpoint.
-
How to Reuse SQL in Spring Boot + MyBatis Using sql and include Tags - Eliminating Query Duplication Across Mappers
Are you copy-pasting the same WHERE conditions or SELECT column lists across multiple Mapper XML files? This article explains how to define SQL fragments with MyBatis's sql tag and reuse them within the same Mapper or across different Mapper XML files using the include tag, how to pass parameters with property, and how to combine this with dynamic SQL tags like foreach.
-
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 Use MyBatis with Spring Boot - Implementation Guide for Mapper Definitions, Dynamic SQL, and Result Mapping
An implementation guide for integrating MyBatis into Spring Boot from scratch. Covers adding the mybatis-spring-boot-starter dependency, defining Mappers using both annotation and XML approaches, dynamic SQL with if and foreach tags, result mapping for joins using resultMap, the safety of #{} versus ${}, and @Transactional integration, all explained with working code.