Agent skill · affaan-m
mybatis-patterns
MyBatis and MyBatis-Spring patterns for mapper design, XML and annotation SQL, result mapping, dynamic SQL safety, transactions, batching, pagination, and query performance. Use when building or reviewing Java persistence code with MyBatis, Spring Boot, MyBatis-Spring, or MyBatis-based legacy applications.
What it needs
About 10k tokens when loaded.
What this skill does
MyBatis Patterns Use MyBatis when SQL control and explicit mappings matter. Keep SQL readable, make mapper contracts small, and put business transactions in the service layer. Pair this skill with springboot-patterns for application structure, database-migrations for schema changes, postgres-patterns or mysql-patterns for engine-specific SQL, and security-review for untrusted input and access-control concerns. When to Activate Adding or reviewing MyBatis mapper interfaces or XML files Choosing between XML mappers, annotation mappers, and generated SQL Designing resultMap mappings, joins, nested collections, or projections Reviewing dynamic SQL, parameter binding, pagination, or batch writes Debugging N+1 queries, slow statements, connection use, or transaction bugs Integrating MyBatis-Spring into Spring Boot or an XML-first legacy application How It Works Use a thin mapper for persistence operations and keep business rules in a service. A typical flow is: Register mappers once, either with @Mapper on each interface or with @MapperScan for a package. Do not mix registration approaches casually. Keep the XML namespace equal to the mapper interface's fully qualified name. Give each statement a stable, descriptive id; treat mapper methods as a persistence API that can be tested independently. Return a domain DTO or projection for read paths instead of exposing a large mutable map when the shape is known. Keep schema changes in migrations. Do not make mapper startup silently create or alter production tables. Examples Parameter Binding and SQL Safety Use #{...} for values. MyBatis binds it as a prepared-statement parameter. Treat ${...} as raw SQL text: it is only appropriate for a value selected from a closed, application-owned allowlist such as a sort-column map. Derive tenantId from the authenticated principal or a server-side tenant context, never from a request field. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills affaan-m/mybatis-patterns