Backend Development 9 min read

Implementation and Comparison of Fluent MyBatis, Native MyBatis, and MyBatis‑Plus for Student Score Statistics

This article presents a typical requirement to calculate count, minimum, maximum, and average scores for three subjects in a student_score table, demonstrates how to fulfill it using raw SQL, then shows step‑by‑step implementations with Fluent MyBatis, native MyBatis XML, and MyBatis‑Plus code generation, and finally compares the three approaches highlighting their pros and cons.

Top Architect
Top Architect
Top Architect
Implementation and Comparison of Fluent MyBatis, Native MyBatis, and MyBatis‑Plus for Student Score Statistics

The article introduces a typical business requirement: compute statistics (count, minimum, maximum, average) for three subjects (English, Math, Chinese) in a student_score table for terms from 2000 onward, with passing scores of at least 60 and a sample size greater than one, sorted by term and subject.

It first provides the raw SQL query that satisfies this requirement, illustrating the use of GROUP BY , HAVING , and ordering clauses.

Next, the article demonstrates how to implement the same query using Fluent MyBatis , showing the generated entity class, the mapper interface method, the XML‑free fluent API call, and a JUnit test that constructs a SummaryQuery parameter object and invokes the mapper.

Then it presents the native MyBatis approach, defining a mapper interface, a parameter POJO annotated with Lombok, and the corresponding XML mapping file that contains the SQL with <foreach> for the subject list.

After that, the article shows the MyBatis‑Plus solution, including a code generator configuration class that sets up database connection, package paths, table fill strategies, and generates entity and mapper code for the student_score table.

The article compares the three implementations, noting that native MyBatis is verbose and cumbersome, Fluent MyBatis offers concise API and IDE assistance, while MyBatis‑Plus simplifies code generation but still relies on hard‑coded strings, which can be error‑prone.

Finally, it concludes with a brief summary, encourages readers to explore the Fluent MyBatis source code for deeper insights, and includes promotional material for related communities and resources.

JavaSQLDatabaseMyBatisORMMyBatis-PlusFluent MyBatis
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.