依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
代码
package com.example.pagehelp.repository;
import com.example.pagehelp.model.Act_hi_taskinst;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface TestRepository extends JpaRepository<Act_hi_taskinst,Long> {
Page<Act_hi_taskinst> findAll(Specification<Act_hi_taskinst> specification, Pageable pageable);
}
package com.example.pagehelp.model;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;
/**
* act_hi_taskinst
* @author
*/
@Entity
@Data
public class Act_hi_taskinst implements Serializable {
@Id
private String id_;
private String procDefId_;
private String taskDefKey_;
private String procInstId_;
private String executionId_;
private String name_;
private String parentTaskId_;
private String description_;
private String owner_;
private String assignee_;
private Date startTime_;
private Date claimTime_;
private Date endTime_;
private Long duration_;
private String deleteReason_;
private Integer priority_;
private Date dueDate_;
private String formKey_;
private String category_;
private String tenantId_;
}
package com.example.pagehelp.service;
import com.example.pagehelp.mapper.ActHiTaskinstDAO;
import com.example.pagehelp.model.ActHiTaskinst;
import com.example.pagehelp.model.ActHiTaskinstExample;
import com.example.pagehelp.model.Act_hi_taskinst;
import com.example.pagehelp.repository.TestRepository;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class TestJPAService {
@Autowired
private ActHiTaskinstDAO actHiTaskinstDAO;
@Autowired
private TestRepository testRepository;
public void testJPA() {
Pageable pageable = PageRequest.of(1, 10);
Page<Act_hi_taskinst> a = testRepository.findAll(pageable);
a.forEach(t -> {
System.out.println("--------------");
System.out.println(t.toString());
});
System.out.println(a.getSize());
System.out.println(a.getTotalPages());
}
}
网友评论