Convert MyBatis Mapper XML to Java interface and vice versa.
MyBatis is a persistence framework that maps SQL statements to Java methods using either XML mapper files or annotation-based Java interfaces. This tool converts between the two styles — if you have an XML mapper and want to migrate to annotation-based development, or vice versa, this tool generates the boilerplate for you instantly.
The XML style keeps SQL separated from Java code in *Mapper.xml files, while the Java annotation style embeds SQL directly in the interface using @Select, @Insert, @Update, and @Delete annotations. Both approaches are fully supported by MyBatis-Plus and Spring Boot's MyBatis integration.
.xml files under resources/mapper/. Easier to manage complex SQL, supports dynamic SQL with <if>, <foreach>, <choose>. Better for long queries.@SelectProvider).BaseMapper<T> with built-in CRUD methods. Custom queries can use either style on top of it.mybatis.mapper-locations=classpath:mapper/*.xml in application.properties@MapperScan("com.example.mapper") on the Spring Boot main class@Mapper on the interface, no XML neededmybatis.configuration.map-underscore-to-camel-case=true to auto-map user_name → userNameFor new Spring Boot projects, use MyBatis-Plus with annotation/BaseMapper for standard CRUD, and XML for complex queries with dynamic conditions. Avoid putting multi-line SQL in annotations — it becomes unreadable. A good rule: if the SQL fits on one line, use an annotation; if it needs dynamic conditions or JOINs, use XML.
Use @SelectProvider(type = UserSqlProvider.class, method = "buildQuery") and implement the SQL builder in a separate provider class using MyBatis's SQL DSL. This keeps dynamic SQL out of annotations while avoiding XML files. For most cases though, XML <if> tags are simpler and more readable.
#{param} is a parameterized placeholder — MyBatis uses a PreparedStatement and the value is safely escaped, preventing SQL injection. ${param} is string substitution — the value is inserted directly into the SQL string. Never use ${} with user-provided values. Only use it for things like dynamic table names or column names that cannot be parameterized.
Use <resultMap> in XML with <association> for one-to-one and <collection> for one-to-many relationships. In annotation style, use @Results with @One or @Many. For simple flat mappings, map-underscore-to-camel-case=true handles most column-to-field name differences automatically.