如何操作PageImpl对象的弹簧启动

时间:2018-07-05 18:39:31

标签: java spring-boot

在这里的工作人员的帮助下,我得到了返回PageImpl类型对象的方法,现在我在获取分页数据时遇到了麻烦,这是搜索方法。 如何创建一个对象,使其可以正确接收getAllPeople返回方法?

public static ArrayList getAllPeople(Connection connection, Pageable pageable) {
ArrayList<peopleDto> peopleList = new ArrayList<>();
DSLContext ctx = null;
peopleDto peopleDto;
try {
    ctx = DSL.using(connection, SQLDialect.MYSQL);
    Result<Record> result = ctx.select()
            .from(people)
            .orderBy(people.GNUM)
            .offset(pageable.getOffset())
            .limit(pageable.getPageSize())
            .fetch();
             count=ctx.fetchCount(ctx.selectFrom(people));

    for (Record r : result) {

        peopleDto = new peopleDto();
        peopleDto.setpeopleID(r.getValue(people.GNUM));
        peopleDto.setName(r.get(people.SNAME));
        peopleDto.setRM(r.get(people.SRM));
        peopleDto.setRG(r.get(people.SRG));
        peopleDto.setCertidaoLivro(r.get(people.SCERT));
        peopleDto.setCertidaoDistrito(r.get(people.SCERTD));
        peopleList.add(peopleDto);
    }
} catch (Exception e) {
    log.error(e.toString());
} finally {
    if (ctx != null) {
    ctx.close();
    }
}
return new PageImpl(peopleList, pageable,count);

}

这里我要分批发送

    public void createPost2() throws IOException, NoSuchAlgorithmException, SQLException {
    ObjectMapper mapper = new ObjectMapper();
    Useful useful = new Useful(config);
    ArrayList<PeopleDto> peopleList = new ArrayList<>();
    String peopleString = null;
     Connection con = config.getConnection();

     Page<PeopleDto> page = new PageImpl<>(peopleList);

    if (page.hasNext()){
        PeopleManager.getAllPeople(con,page.nextPageable());

        int sizeRecords = peopleList.size();
        try {
            peopleString = useful.convertToJson(peopleList);
            peopleStringWithSecurity = useful.securityJson(peopleString);
        } catch (JsonProcessingException e) {
            log.error(e.toString());
        }

        RestTemplate restTemplate = new RestTemplate();
        String url = "myRestService";
        HttpHeaders headers;
        headers = getHeaders(sizeRecords, peopleString);
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<String> entity = new HttpEntity<>(peopleWithSecurity, headers);
        String answer = restTemplate.postForObject(url, entity, String.class);
        log.info(answer);
    }
}

0 个答案:

没有答案