About BitSnippets

A small, opinionated publication about the Java libraries that quietly run production systems.

Why this site exists

Searching for “MyBatis dynamic SQL example” returns a hundred pages that all show the same four-line <if> snippet and stop. None of them mention that <where> only strips a leading AND, that OGNL treats 'Y' as a character and not a string, or that a <foreach> over ten thousand IDs will blow past your database's parameter limit.

BitSnippets is built around the belief that the interesting part of any framework is exactly the part that short tutorials skip. So we write long ones.

Editorial principles

  1. Every snippet compiles. Code is written inside a real project, run against a real database, and only then pasted in. Imports and configuration are shown when they are not obvious.
  2. Versions are stated. A tutorial without a version number has a shelf life of about eight months. Ours name the exact MyBatis, Spring Boot and JDK releases used.
  3. Trade-offs, not evangelism. MyBatis is excellent at some things and a poor fit for others. We say which is which, including where Hibernate or plain JDBC wins.
  4. Failure modes get equal billing. Every chapter ends with the mistakes people actually make — the stack traces, the silent nulls, the N+1 that only appears once the table has a million rows.
  5. No dark patterns. No newsletter interstitials, no “read 3 free articles”, no paywall. The site is funded by advertising instead — clearly labelled, never mixed into the prose, and never a paid link inside a tutorial. You can decline personalised ads, or decline personalised advertising, without losing access to anything.

How the site is built

Deliberately boring: hand-written HTML, one stylesheet, two small scripts, and SVG diagrams authored by hand so they stay crisp and readable in both light and dark themes. There is no build step, no framework and no runtime dependency — the entire site can be served from any static host or opened directly from disk.

LayerChoiceWhy
MarkupStatic HTML5Fast, indexable, zero runtime cost
StylingOne CSS file, custom propertiesTheming without a preprocessor
Highlighting~150 lines of vanilla JSNo 400 KB syntax library for six languages
DiagramsHand-authored SVGScales, prints, and stays accessible via titles
SearchClient-side indexNo server, no analytics on your queries
AdsLazy, height-reserved slotsRevenue without wrecking layout stability

Who this is for

Backend developers who are comfortable with Java and SQL, and who want to understand the library rather than memorise its snippets. If you can read a stack trace and write a JOIN, you are the target reader. If you are brand new to SQL, read a SQL primer first — MyBatis assumes you already know what you want the database to do.

Corrections welcome

Found a mistake, an outdated API, or a pitfall we missed? Tell us on the contact page. Technical corrections get priority over everything else.

Reusing the material

Code snippets in the tutorials are provided as-is for you to copy into your own projects, commercial or otherwise. Prose and diagrams are © BitSnippets — quote a paragraph with attribution and a link, but please do not republish whole chapters.

Start with the MyBatis course →