MyBatis: From Beginner to Expert

Liu ZenghuiPublishing House of Electronics Industry2017

No rating yet
Word count
430 words
Chapters
12
ISBN
9787121317972

Tags

Computing Software Tutorials Code GenerationDev EnvironmentPersistence FrameworkProgramming DesignField CasesImplementation PrinciplesStep by StepSource Code AnalysisFrom Beginner to Master

Summary

MyBatis: From Beginner to Expert is a Chinese technical book by Liu Zenghui (the original author of the PageHelper pagination plugin and the general Mapper) explaining the MyBatis persistence framework. The book opens with the simplest MyBatis query, first guiding readers through setting up a Maven development environment to get the framework "up and running," and then unfolds step by step. The fundamentals section follows two threads—XML configuration and annotations—to explain systematically how to write select, insert, update, and delete statements and how to use multi-parameter interfaces, and it analyzes the implementation principle of dynamic proxies for Mapper interfaces. The advanced section focuses on MyBatis's most powerful feature, dynamic SQL (if, choose, where, set, trim, foreach, bind, multi-database support, and OGNL), as well as the configuration and operation of the MyBatis Generator code generator. The book also covers in detail advanced result mapping (one-to-one, one-to-many, discriminators), stored procedures, enums and custom type handlers, first-level and second-level caching with EhCache and Redis integration, and interceptor plugin development, and it demonstrates step by step how to integrate with Spring, Spring MVC, and Spring Boot. The final chapter introduces the MyBatis open-source project through Git and GitHub, using source code and test cases to help readers understand the framework's internal mechanisms. The book is accompanied by a wealth of directly runnable example code and emphasizes a learning path of "first learn to use it, then understand the principles."

Editor's review

市面上讲 MyBatis 的中文书不少,但由框架周边生态核心贡献者亲手写成的系统教程并不常见。刘增辉是 MyBatis 官方推荐的分页插件 PageHelper 与通用 Mapper 的作者,对源码与真实工程问题都很熟悉,因此这本书在“怎么用”和“为什么这样设计”之间衔接得比较自然。 结构上,全书沿“跑起来—基本 CRUD—动态 SQL—代码生成器—高级映射—缓存—插件—框架集成—源码”的顺序推进,章节之间层层递进,几乎没有跳跃。每章都配有可运行的示例代码和测试,读者可以边敲边验证,而不是只读概念。 尤其值得称道的是对动态 SQL、拦截器插件和二级缓存的讲解:这三块是日常开发中最容易踩坑的地方,书中既给出配置细节,也点出最佳实践与注意事项。最后两章关于 Spring Boot 集成与源码阅读的内容,则可以把学习者从“会用框架”带到“理解框架”。对于需要长期与 MyBatis 打交道的中级 Java 开发者,这是一本能反复翻查的书。

Who it's for

A good fit for

Not a good fit for

Reading tips

  1. 建议边读边敲:按章节顺序在本机搭建 Maven 项目,运行书中示例并自行修改 SQL 验证结果。
  2. 第4章动态 SQL 与第8章插件开发可反复精读,把常用标签与拦截器签名整理成自己的速查笔记。
  3. 读缓存与集成章节时,最好配一个真实小项目迁移练习,体会配置差异与踩坑点。
  4. 最后再读第11章源码部分,重点跟进一条增删改查的完整调用链,不必逐行通读。

About the publisher

Publishing House of Electronics Industry China · Founded in 1982

The Publishing House of Electronics Industry is a comprehensive publisher distinguished by its focus on electronic information and related fields. Judging from the more than 3,000 titles in its catalogue, its publishing covers programming and design, artificial intelligence, computer science, finance and economics, photography, and social sciences, attending both to cutting-edge technology and to general readers. Representative titles include Factor Investing: Methods and Practice, x86 Assembly Language: From Real Mode to Protected Mode, The RISC-V Reader, Artificial Intelligence: Speech Recognition, Understanding and Practice, Phased Array Radar Technology, Radar Target Characteristics, and 100 Go Mistakes and How to Avoid Them, most of which centre on technical methods and engineering practice. Its authors include Shi Chuan, Li Zhong, Wang Xiaobo, David Patterson, Andrew Waterman, and Yu Zihao, among others from China and abroad. Owing to limited public information, no further publishing features are elaborated here.

Contents

  1. Chapter 1 Getting Started with MyBatis (Introduction to MyBatis, Creating a Maven Project, Simple Configuration to Get MyBatis Running)
  2. Chapter 2 Basic Usage of MyBatis in XML (Permission Control Requirements, select/insert/update/delete, Multiple Interface Parameters, Implementation Principle of Mapper Interface Dynamic Proxies)
  3. Chapter 3 Basic Usage of MyBatis with Annotations (@Select, @Insert, @Update and @Delete, Provider Annotations)
  4. Chapter 4 MyBatis Dynamic SQL (if, choose, where/set/trim, foreach, bind, Multi-Database Support, OGNL)
  5. Chapter 5 MyBatis Code Generator (Detailed XML Configuration, Configuration Reference Examples, Running MyBatis Generator, Introduction to Example)
  6. Chapter 6 Advanced MyBatis Queries (Advanced Result Mapping, Stored Procedures, Using Enums or Other Objects)
  7. Chapter 7 MyBatis Cache Configuration (First-Level Cache, Second-Level Cache, Integrating EhCache, Integrating Redis, How Dirty Data Arises and How to Avoid It, When to Use Second-Level Cache)
  8. Chapter 8 MyBatis Plugin Development (Interceptor Interface and Signature, Underscore-to-CamelCase Plugin, Pagination Plugin)
  9. Chapter 9 Integrating MyBatis with Spring (Maven Web Project, Integrating Spring and Spring MVC, Integrating MyBatis, Examples)
  10. Chapter 10 Integrating MyBatis with Spring Boot (Basic Spring Boot Project, Integrating MyBatis, MyBatis Starter Configuration, Simple Examples)
  11. Chapter 11 The MyBatis Open-Source Project (Getting Started with Git, Getting Started with GitHub, Explaining the MyBatis Source Code, MyBatis Test Cases)
  12. Appendix Type Handlers (TypeHandler)

FAQ

这本书适合零基础学习 MyBatis 吗? 书中从搭建 Maven 项目和第一个查询开始,入门门槛不高;但仍假定读者会 Java 语法和基本 SQL,完全零基础建议先补齐这两项,再按章节顺序阅读。
书中的示例代码使用什么版本的技术栈? 本书以 Maven 构建项目,示例基于 XML 与注解两种方式使用 MyBatis,并涉及 MyBatis Generator、EhCache、Redis、Spring、Spring MVC 与 Spring Boot 的集成配置。具体版本以书中示例为准,实际动手时建议按当前稳定版本调整依赖。
这本书和市面上其他 MyBatis 书有什么区别? 作者是 PageHelper 分页插件与通用 Mapper 的原作者,书中对插件机制、动态 SQL、缓存等实战细节的讲解更贴近真实项目,并专门安排了源码与测试用例阅读章节。
读完能直接上手公司项目吗? 基本用法、动态 SQL、代码生成器与 Spring Boot 集成都覆盖到了,可以支撑常见 CRUD 开发;但分布式事务、分库分表等进阶话题需要另行学习。

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

About the author

Liu Zenghui Author

Liu Zenghui is an author active in the field of computer technology writing. Public information about him is currently limited, and his detailed biography and educational background cannot yet be confirmed. Judging from the available work, his writing focuses on the practical application and introductory teaching of software development tools. His representative book, MyBatis: From Beginner to Mastery, is aimed at learners of the Java persistence framework MyBatis and covers both fundamental knowledge and advanced usage, offering reference value for readers in the computer and software learning category. The book is a typical technical tutorial, organizing content progressively to help readers understand core aspects such as framework configuration, mapping, and queries. Liu Zenghui's writing style is practical, emphasizing operability and step-by-step learning, making it suitable for beginners and self-learners who wish to systematically master development tools. Since only one of his works is included in the library, more materials are needed to clarify his other writings and professional focus.