使用Mybatis 从MySQL当中随机获取指定数量的数据
2022年9月17日
1 2 3 4 5 6 7 8 9 10 |
@Override public List<ExampleItems> randomCount(Integer numbers) { Page<ExampleItems> page = new Page<>(); page.setSize(numbers); page.setCurrent(1); return this.page(page, Wrappers.<ExampleItems>lambdaQuery().apply(" id >= (SELECT FLOOR(MAX(id) * RAND()) FROM fx_example_items)") .orderBy(true, true, ExampleItems::getId) ).getRecords(); } |