Spring JdbcTemplate:如何限制选定的行? [英] Spring JdbcTemplate: how to limit selected rows?
问题描述
我正在使用Spring JdbcTemplate
接口从MS SqlServer数据库中获取数据.
在文档中,我看到有setMaxRows()
方法可以为所有查询设置限制,但是如果我想仅限制选择呢?
I'm using Spring JdbcTemplate
interface for fetching data from a MS SqlServer DB.
In the documentation I see there is the setMaxRows()
method to set a limit for all the queries, but what if I want to limit only a select?
有没有办法以可配置"的方式仅为特定的被调用查询设置限制?
Is there a way to set a limit only for a specific invoked query in a "configurable" way?
推荐答案
可以通过将限制直接放入查询中来限制特定查询的结果集.请查阅数据库供应商的文档,以查看它是否支持例如LIMIT
.
Limiting the result set of a specific query can be done by putting the limit directly into the query. Consult your DB vendor documentation to see if it supports for example LIMIT
.
MySQL上的示例:SELECT * FROM EMPLOYEE LIMIT 10
Example on MySQL: SELECT * FROM EMPLOYEE LIMIT 10
这篇关于Spring JdbcTemplate:如何限制选定的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!