Spring boot jpa 获取list前10条记录

结果图:

如图:取出list中前10条记录,用的是spring boot 中集成的 jpa格式。

Repository:

List findByTradingcodeContaining(Pageable pageable, String code);
service:

public List findStockCodeAndStockNameByStockCode(String StockCode){
    PageRequest pr = new PageRequest(0, 10);
    List list = stockRepository.findByTradingcodeContaining(pr, StockCode);
    return list;
}
Controller:

@GetMapping(value = "/findStock")
public Result findStockByCode(@RequestParam(value = "code",required = false) String code,
                              @RequestParam(value = "name",required = false) String name){
    List list = null;
    if (!StringUtils.isEmpty(code)) {
        list = stockService.findStockCodeAndStockNameByStockCode(code);
    }else if (!StringUtils.isEmpty(name)) {
        list = stockService.findStockCodeAndStockNameByStockName(name);
    }
    return ResultUtil.success(list);
}

你可能感兴趣的:(jpa,spring,boot)