@Query
Marks an interface method to execute a query that can return a result set.
info
value supports string arrays. Elements are joined with spaces, convenient for multi-line writing.
Example: query a user list
@SimpleMapper
public interface UserMapper {
@Query("select * from users where id > #{id}")
List<User> listUsers(@Param("id") long searchId);
}
Pagination Query
Add a Page parameter to the method arguments for pagination:
// Return List
@Query("select * from users where id > #{id}")
List<User> listUsers(@Param("id") long searchId, Page page);
// Return PageResult (includes total count and total pages)
@Query("select * from users where id > #{id}")
PageResult<User> pageUsers(@Param("id") long searchId, Page page);
Properties
| Property | Description |
|---|---|
| value | Required The query statement to be executed. |
| statementType | Optional JDBC query mode. Default Prepared- Statement → java.sql.Statement- Prepared → java.sql.PreparedStatement- Callable → java.sql.CallableStatement |
| timeout | Optional Query timeout in seconds, calls Statement.setQueryTimeout(int). Default -1 |
| fetchSize | Optional Rows to fetch at a time, calls Statement.setFetchSize(int). Default 256 |
| resultSetType | Optional Result set type: FORWARD_ONLY, SCROLL_INSENSITIVE, SCROLL_SENSITIVE, DEFAULT (default) |
| resultSetExtractor | Optional Configure a ResultSetExtractor for result set processing (ignored when bindOut is set) |
| resultRowCallback | Optional Configure a RowCallbackHandler for result set processing (ignored when bindOut is set) |
| resultRowMapper | Optional Configure a RowMapper for result set processing (ignored when bindOut is set) |
| resultTypeHandler | Optional Configure a TypeHandler for result set processing (ignored when bindOut is set) |
| bindOut | Optional Bind output parameters, for use with stored procedures or multiple result sets. When set, the return type must be Map<String,Object> |