springboot中使用自定义的分页工具PageUtils
分页工具要包括的主要功能:
1、数据查询功能,最基础的
2、数据总条数和总页数,方便提供给前端处理
3、规范化的数据形式,这里使用json
代码
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import java.util.*;
/**
* 分页工具
*/
//@Compoent注解,将该类加入到Spring容器中
@Component
//@Slf4j注解,打印日志时使用
@Slf4j
public class PageUtil {
//这里使用org.springframework.jdbc.core.JdbcTemplate,使用jdbc的方式
@Autowired
private JdbcTemplate jdbc;
/**
*该方法统计查询的所有数据
* @param sql
* @param cla
* @return
*/
public Object queryOneColumnForSigetonRow(String sql, Class cla){
Object result=null;
try{
result=