Jpa 根据字段排序

 方法一:Pageable

    /**
     * 查询所有,根据"xh"字段升序排序
     */
    @RequestMapping(value = "/cVendorListUI")
    public String cvendorList(Model model, @PageableDefault(value = 20, sort = {"xh"}, direction = Sort.Direction.ASC) Pageable pageable) {
        Page cVendors = cVendorService.findAllCVendor(pageable);
        model.addAttribute("page", cVendors);
        return ROOT + "/cVendorListUI";
    }

方法二:Sort

Sort.Order order = Sort.Order.asc("id");
Sort sort = Sort.by(order);
List vPurchasesAll = vPurchaseRepository.findAll(sort);     //查询VPurchase的所有数据,按照id升序获取

 

你可能感兴趣的:(Jpa)