org.apache.ibatis.jdbc.SQL类的OFFSET函数指定从哪行(行索引的位置)开始查询,LIMIT函数指定最多返回多少行。
注意:第一行的行索引是0,而不是1。
示例:
mysql数据库user表的记录:
mapper接口文件:
package com.thb.mapper;
import java.util.List;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.jdbc.SQL;
import com.thb.model.User;
public interface UserMapper {
@Results(value = {
@Result(property = "id", column = "id", id = true),
@Result(property = "userName", column = "user_name"),
@Result(property = "homeTown", column = "home_town")
})
@SelectProvider(type = UserSqlBuilder.class, method = "selectManyUsers")
List<User> selectManyUsers();
public static class UserSqlBuilder {
public static String selectManyUsers() {
return new SQL() {{
SELECT("id, user_name, home_town");
FROM("user");
LIMIT(1);
OFFSET(1);
}}.toString();
}
}
}
运行输出: