Skip to main content

@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

PropertyDescription
valueRequired The query statement to be executed.
statementTypeOptional JDBC query mode. Default Prepared
- Statementjava.sql.Statement
- Preparedjava.sql.PreparedStatement
- Callablejava.sql.CallableStatement
timeoutOptional Query timeout in seconds, calls Statement.setQueryTimeout(int). Default -1
fetchSizeOptional Rows to fetch at a time, calls Statement.setFetchSize(int). Default 256
resultSetTypeOptional Result set type: FORWARD_ONLY, SCROLL_INSENSITIVE, SCROLL_SENSITIVE, DEFAULT (default)
resultSetExtractorOptional Configure a ResultSetExtractor for result set processing (ignored when bindOut is set)
resultRowCallbackOptional Configure a RowCallbackHandler for result set processing (ignored when bindOut is set)
resultRowMapperOptional Configure a RowMapper for result set processing (ignored when bindOut is set)
resultTypeHandlerOptional Configure a TypeHandler for result set processing (ignored when bindOut is set)
bindOutOptional Bind output parameters, for use with stored procedures or multiple result sets. When set, the return type must be Map<String,Object>