Skip to main content
Hint

This article is generated by AI translation.

Method Annotations

By annotating Mapper interface methods, you separate SQL from calling logic without writing JDBC boilerplate code.

Define a Mapper interface
@SimpleMapper
public interface UserMapper {
@Query("select * from users where id > ?")
List<User> listUsers(long searchId);
}
Use the Mapper
Session session = config.newSession(dataSource);
UserMapper mapper = session.createMapper(UserMapper.class);
List<User> result = mapper.listUsers(2);
Tip

How you obtain a Session depends on your project architecture. See Framework Integration for details.

Annotation List

AnnotationPurposeExample Scenario
@QueryExecute a query and return a result setSELECT queries, pagination
@InsertExecute an INSERT statementInsert records, retrieve auto-generated keys
@UpdateExecute an UPDATE statementUpdate records
@DeleteExecute a DELETE statementDelete records
@ExecuteExecute any statement (DML/DDL)Create tables, batch operations, multiple result sets
@CallCall a stored procedureStored procedure/function calls
@SegmentDefine a reusable SQL fragmentReferenced via @{macro,...} rules

Common Notes

  • All annotations that accept SQL (value attribute) support string arrays; array elements are joined with spaces for multi-line readability
  • SQL can use Rules for dynamic capabilities (conditional concatenation, IN queries, etc.)
  • The statementType attribute options are Statement, Prepared (default), and Callable