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
| Annotation | Purpose | Example Scenario |
|---|---|---|
| @Query | Execute a query and return a result set | SELECT queries, pagination |
| @Insert | Execute an INSERT statement | Insert records, retrieve auto-generated keys |
| @Update | Execute an UPDATE statement | Update records |
| @Delete | Execute a DELETE statement | Delete records |
| @Execute | Execute any statement (DML/DDL) | Create tables, batch operations, multiple result sets |
| @Call | Call a stored procedure | Stored procedure/function calls |
| @Segment | Define a reusable SQL fragment | Referenced via @{macro,...} rules |
Common Notes
- All annotations that accept SQL (
valueattribute) 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
statementTypeattribute options areStatement,Prepared(default), andCallable