繁体   English   中英

Spring Data MongoRepository for int values

[英]Spring Data MongoRepository between for int values

有一个 class 例如(这是kotlin ,但代码很容易理解):

@Repository
interface ScoresRepository : MongoRepository<Score, String> {
    fun countAllByScoreIsBetween(min: Int, max: Int): Int
}

@Document
data class Score(
    @Id var score: Int,
)

之间是包容的还是排斥的? 也就是说,如果我的分数是 1-10,并且我调用: countAllByScoreIsBetween(3,6)我会得到 4 还是 2? 或者可能是其他东西 - 底部是包容性的,顶部是专有的?

测试(使用testcontainers )显示了这一点:

@Autowired
lateinit var scoresRepository: ScoresRepository

@Test
fun test() {
    for (i in 1..10) {
        scoresRepository.save(Score(score = i))
    }

    val count = scoresRepository.countAllByScoreIsBetween(3, 6)

    assertThat(count).isEqualTo(2)
}

据我所知,这两个参数都不包括在内。 也就是说, Between表示值之间的所有内容,不包括值本身。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM