Reference: https://blog.csdn.net/qq_40715775/article/details/83153808
rely:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency>
domain:
@NoArgsConstructor @AllArgsConstructor @Document(collection = Constant.MILESTONE_WORK_TABLE) public class MilestoneInfo implements Serializable { private static final long serialVersionUID = 1L; @Id private String id; private String mawb;}
config:(application.propeties)
#spring.data.mongodb.uri=mongodb://userName:password@ip:port/database spring.data.mongodb.database=SERVICE-sea-test spring.data.mongodb.host=127.0.0.1 spring.data.mongodb.port=27017 #spring.data.mongodb.username=root #spring.data.mongodb.password=root
repository:
@RepositoryRestResource(path = "worktable",collectionResourceRel = "worktables") public interface WorkTableRepository extends MongoRepository<MilestoneInfo, String>{ // @Query("{\"sendtimes\":{\"$regex\":?0}, \"courierbillNo\": ?1}") List<MilestoneInfo> findByReasonAndCustomerAndSendTimesLessThan(String reason, String customer,int sendTimers); // @Query("{\"sendtimes\":{\"$regex\":?0}, \"success\": ?1}") List<MilestoneInfo> findByMawbOrCustomerOrOrderNoOrStatusOrCourierBillNoOrSendTimesLessThan(String mawb, String customer,String orderNo,String status,String courierbillNo,Integer sendTimers); List<MilestoneInfo> findByMawbAndCustomerAndOrderNoAndStatusAndCourierBillNoAndSendTimesLessThan(String mawb, String customer,String orderNo,String status,String courierbillNo,Integer sendTimers); }
web:
@GetMapping ( "Finds / {Page} / {size}" ) public Page <MilestoneInfo> findByPageSort (@PathVariable ( "Page") int Page, @ PathVariable ( "size") int size) { // the Sort Sort the Sort = new new ( "ID"); the Sort Sort = new new the Sort (Direction.ASC, "MAWB" ); // the Pageable query interface for the configuration page, PageRequest its implementation class, the plant can be created by the method provided PageRequest: // public PageRequest of static (Page int, int size) // may also be added to the sort PageRequest: // public static PageRequest of (Page int, int size, the Sort Sort) PageRequest Pageable = PageRequest.of(page - 1 ,size,sort); Page<MilestoneInfo> pagedatas = workTableRepository.findAll(pageable); return pagedatas; }