springboot + jpa
Posted yifanSJ
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot + jpa相关的知识,希望对你有一定的参考价值。
例子
public void aaa() { //1. @Query List<LogisticsFinanceDayOrder> list1 = logisticsFinanceDayOrderDao.ccc(); LogisticsFinanceDayOrder list2 = logisticsFinanceDayOrderDao.ccc2("5"); List<String> list3 = logisticsFinanceDayOrderDao.ccc3("18日"); //2. 排序查询 Sort sort=new Sort(Sort.Direction.DESC,"id"); List<LogisticsFinanceDayOrder> list = logisticsFinanceDayOrderDao.findAll(sort); System.out.println("ccc"); //3. 分页排序查询 PageRequest pageRequest = PageRequest.of(0,4,sort); Page<LogisticsFinanceDayOrder> page = logisticsFinanceDayOrderDao.findAll(pageRequest); System.out.println("ccc"); //4. 实体匹配查询 LogisticsFinanceDayOrder logisticsFinanceDayOrder = new LogisticsFinanceDayOrder(); //logisticsFinanceDayOrder.setId("5"); logisticsFinanceDayOrder.setDescription("18日"); ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("description", ExampleMatcher.GenericPropertyMatchers.startsWith()); Example example = Example.of(logisticsFinanceDayOrder,exampleMatcher); List<LogisticsFinanceDayOrder> l = logisticsFinanceDayOrderDao.findAll(example); } @Repository public interface LogisticsFinanceDayOrderDao extends BaseDao<LogisticsFinanceDayOrder>, LogisticsFinanceDayOrderDaoCustom { @Query("from LogisticsFinanceDayOrder") public List<LogisticsFinanceDayOrder> ccc(); @Query("from LogisticsFinanceDayOrder where id = ?1") public LogisticsFinanceDayOrder ccc2(String id); @Query("select orderNo from LogisticsFinanceDayOrder where description like CONCAT(:description,‘%‘)") public List<String> ccc3(@Param("description") String description); }
以上是关于springboot + jpa的主要内容,如果未能解决你的问题,请参考以下文章
springboot(十五):springboot+jpa+thymeleaf增删改查示例
SpringBoot系列——Spring-Data-JPA(升级版)