---
name: Mybatis Expert
slug: mybatis-expert
category: AI Engineering
description: Mybatis Expert explains MyBatis mapper interfaces, XML mapping, dynamic SQL, result maps, pagination, batch operations, and caching. Use it when writing or reviewing MyBatis data access code.
github: "https://github.com/val1813/kwcode/tree/master/kaiwu/builtin_experts/mybatis"
language: Python
stars: 688
forks: 92
install: "npx degit https://github.com/val1813/kwcode/tree/master/kaiwu/builtin_experts/mybatis ~/.claude/skills/mybatis"
installs_to: ~/.claude/skills/mybatis
source_path: kaiwu/builtin_experts/mybatis/SKILL.md
collection_size: 19
category_size: 2451
collection_url: "https://dirskills.com/collections/val1813/kwcode"
added: 2026-08-12T04:43:49.359Z
last_synced: 2026-08-12T04:43:49.359Z
canonical_url: "https://dirskills.com/skills/mybatis-expert"
---

# Mybatis Expert

Mybatis Expert explains MyBatis mapper interfaces, XML mapping, dynamic SQL, result maps, pagination, batch operations, and caching. Use it when writing or reviewing MyBatis data access code.

**Install:**

```bash
npx degit https://github.com/val1813/kwcode/tree/master/kaiwu/builtin_experts/mybatis ~/.claude/skills/mybatis
```

## README

## 领域知识

- Mapper接口方法名与XML中id一一对应，namespace为接口全限定名
- 动态SQL标签：<if test=""> 条件拼接、<choose>/<when>/<otherwise> 多分支、<foreach> 集合遍历
- ResultMap：一对一用<association>，一对多用<collection>，嵌套查询用select属性
- 参数传递：单参数直接用#{param}，多参数用@Param注解或封装DTO
- #{} 预编译防注入，${} 字符串替换仅用于动态表名/列名
- 分页：配合PageHelper插件，Mapper方法前调用PageHelper.startPage()
- 批量操作：insert用<foreach>拼接VALUES，update用<foreach>+CASE WHEN
- 缓存：一级缓存SqlSession级别默认开启，二级缓存需在XML加<cache/>
- 通用字段（create_time/update_time）用拦截器自动填充
- XML文件放在 resources/mapper/ 目录，与接口包路径对应

## 经验规则（自动生成）
