Hint
This article is generated by AI translation.
Quick Lookup
Note
This page skips the API overview and organizes links by usage scenarios for quick lookup.
Insert,Delete,Update
- Use raw SQL Statements.
- Use annotations @Insert, @Delete, @Update.
- Use the Fluent API to Insert, Delete, Update.
- Use the Common Mapper interface.
- In a Mapper file, use <insert> to insert data.
- In a Mapper file, use <selectKey> to handle auto-increment IDs during insert.
- In a Mapper file, use <update> / <delete> to update or delete data.
Basic Query
- 使用 SQL 语句 查 询结果集、查询对象、查询键值对、查询值/值列表、流式查询
- Execute statements and Multiple ResultSet.
- Define queries on interfaces with @Query.
- Use the Fluent API to Fetch one object, List, Count.
- Use the Fluent API for Group by and Order by.
- In a Mapper file, use <select> to query and <sql> to define fragments.
Arguments
- In dynamic SQL, pass parameters via SQL injection (assess injection risks yourself).
- Pass parameters by Positional or using Named positional.
- Pass parameters by Named and further access values with OGNL.
- Use SqlArgSource or PreparedStatement for parameters.
- Use Rules to make parameters dynamic in SQL.
Pagination
- Use pagination in the Fluent API.
- In Mapper interfaces, add paging params to @Query methods for pagination.
- Paginate via the Common Mapper (includes sorting and null ordering).
- Use Session queryStatement / pageStatement overloads for pagination.
- After binding Mapper interfaces to XML, use a Page object for pagination.
Dynamic Command
- Inject predefined fragments with MACRO rules (assess injection risks).
- Use IFTEXT rules or
${...}for injection (assess injection risks). - Enhance SQL with AND, OR, SET.
- IN auto-generates
(?,?,?,?)based on collection size. - Conditional rules: IFAND, IFOR, IFSET, IFIN.
- Rules can process SQL fragment, not just a single parameter.
- In Mapper files, use <if>, <choose> / <when> / <otherwise>.
- In Mapper files, use <trim> / <where> / <set> to refine SQL generation.
- In Mapper files, use <foreach> for loops.
Object mapping
- Use @Table and @Column annotations for mapping.
- Use camel case to auto-map properties to columns.
- Handle case sensitivity and keyword columns.
- Control column participation via write policy (insert/update).
- Choose primary key strategies via @Column
keyType(Key Generators). - In Mapper files, use <entity> to describe mappings in XML.
- In Mapper files, <resultMap> is similar to <entity> but only for query result mapping.
- Use auto-mapping to simplify configuration.
- With the builder, Statement Templates decide generated SQL elements.
Stored procedures
- Use SQL to Stored Procedures Call.
- Set parameter mode to OUT.
- Use mode
cursorto read cursor arguments. - Use @Call to execute procedures.
Executing SQL
- Batches SQL statements.
- Load a Scripts file.
- Execute any statement with @Execute.
- In Mapper files, use <execute> for arbitrary SQL.
Results
- Use List/Map across APIs to collect query results.
- Use RowMapper to map each row:
- ColumnMapRowMapper converts rows to Map and returns List/Map.
- SingleColumnRowMapper handles single-column results into a List.
- BeanMappingRowMapper maps rows to beans.
- MapMappingRowMapper maps rows to maps.
- Use ResultSetExtractor to customize ResultSet handling.
- dbVisitor ResultSetExtractor implementations used internally.
- Use RowCallbackHandler to process rows without collecting them.
- Example: MySQL streaming large tables.
Type Handler
- Specify a type handler via the TypeHandler option in SQL parameters.
- Use the @Column TypeHandler option for abstract types, enums, JSON serialization.
- dbVisitor provides many handlers; check built-ins first:
- Map enums via EnumOfValue or EnumOfCode.
- The serialization auto-detects Fastjson2, Fastjson, Jackson, Gson in that order.
- With JTS on the classpath, dbVisitor can handle WKB/WKT geospatial data.
- dbVisitor also supports InputStream/Reader and Array types.
Redis support
- See the 140+ Redis commands supported by dbVisitor: Commands.
- Learn how dbVisitor handles Redis data types (String, Hash, List, Set, Sorted Set).
- Use JdbcTemplate to Execute commands.
- Use @Insert, @Update, @Delete on Mapper interfaces for Annotation-driven Redis operations.
- In Mapper files, configure commands via tags: Mapper File.
MongoDB support
- See MongoDB commands supported by dbVisitor: Commands.
- Use JdbcTemplate to Execute commands.
- Use Fluent API.
- Use Common Mapper.
- On Mapper interfaces, use @Insert, @Update, @Delete for Annotation-driven operations.
- In Mapper files, configure commands via tags: Mapper File.
Database transactions
- Spring projects: use Spring Annotations.
- Solon projects: use Solon Annotations.
- Guice and Hasor: use dbVisitor @Transactional.
- Without bytecode enhancement, enhance objects via TransactionHelper, then use @Transactional.
- Alternatively, control transactions via Java code or templates.
Framework integrations
- Use dbvisitor-guice with Google Guice.
- Use dbvisitor-spring with Spring / Spring Boot.
- Use dbvisitor-solon with Solon.
- Use dbvisitor-hasor with Hasor.