SSM框架+pagehelper分页+layUI的table数据表格实现分页demo

实现table的分页,如果查询的数据是多表查询,分页查询时只有第一页,解决方法:可以对查询的数据正常分页,再写个SQL语句查询数据总个数

配置:SqlSessionFactoryBean中


    
    
    
    
    
        
            
            
                
                    
                        
                        mysql
                        
                        true
                    
                
            
        
    

不使用maven,需要添加jar包(版本根据情况)
jsqlparser-1.0.jar
pagehelper-5.1.4.jar

demo结构

DAO层:
public class Student {
    private String id;

    private String name;

    private Integer age;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id == null ? null : id.trim();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}

**mapper层;**
public interface StudentMapper {

    List selectAll();

    int count();
}

**service层**
public interface StudentService {

    List selectAll(Integer pageNum,Integer pageSize);

    int count();
}

**serviceImpl层**
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper stu;

    @Override
    public List selectAll(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List students = stu.selectAll();
        return students;
    }

    @Override
    public int count() {
        return stu.count();
    }
}

**controller层**
@RestController
@RequestMapping("/findAll")
public class FindAll {
    @Autowired
    private StudentServiceImpl stu;

    /**
     * layui中table表分页,默认是page=1,limit=10,与pagehaper参数对应,
     * layui中还需要数据的总个数count
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/student")
    public String student(@RequestParam("page") Integer pageNum, @RequestParam("limit") Integer pageSize) throws Exception {
        List students = stu.selectAll(pageNum, pageSize);
        int count = stu.count();
        JSONObject json = new JSONObject();
        json.put("code", 0);
        json.put("count", count);
        json.put("data", students);
        return json.toString();
    }
}

**xml文件**



  
    
    
    
  
  
  
  


**HTML页面和数据绑定**



    
    layui
    
    
    
    
    



你可能感兴趣的:(SSM框架+pagehelper分页+layUI的table数据表格实现分页demo)