LayUI table page display problem

LayUI table pagination displays all back-end data, no paging problem

First of all, my understanding is that if I send all the data back to the front-end LayUI table, it will help me paginate, but the result is not like this. In fact, the work of paging is still in the backend. When using table to request data through the URL, it will also carry two parameters of page and limit (respectively, the current page number and the number of limits displayed on a page). We need to get these two parameters in the backend. value, complete pagination
1, first upload the code

table.render({
    
    
            elem: '#currentTableId',
            // url: '[[@{/api/table-patient.json}]]',
            url: '[[@{/patientList}]]',
            page: true,
            cols: [
                [
                {
    
    type:'numbers'},
                {
    
    field: 'patientName', width: 120, title: '姓名', align: "center"},
                {
    
    field: 'patientIdNumber', title: '身份证', width: 250, minWidth: 80, align: "center"},
                {
    
    field: 'patientSex', width: 80, title: '性别', align: "center"},
                {
    
    field: 'patientAge', width: 80, title: '年龄', align: "center"},
                {
    
    field: 'patientBirthday', width: 160, title: '出生日期', align: "center"},
                // {field: 'time', width: 80, title: '初复诊', align: "center"},
                {
    
    field: 'room', width: 120, title: '科室', align: "center"},
                {
    
    field: 'doctor', width: 120, title: '医生', align: "center"},
                {
    
    field: 'cost', width: 100, title: '费用', align: "center"},
                {
    
    title: '操作', minWidth: 50, templet: '#currentTableBar', fixed: "right", align: "center"}
            ]
            ]
        });

This is LayUI code written in HTML to request data from patientList (a controller).
2. The following is the patientList code

 @RequestMapping("/patientList")
    @ResponseBody
    public PatientJson patientList(String page, String limit){
    
    
        int pageTemp = Integer.parseInt(page);
        int limitTemp = Integer.parseInt(limit);
        List<PatientList> patientLists = new ArrayList<>();
        PatientList patientList;
        for (int i = 0; i<30; i++){
    
    
            patientList = new PatientList();
            patientList.setPatientIdNumber("100000"+i*5);
            patientList.setPatientName("xlk"+i);
            patientList.setPatientAge(i*8);
            patientList.setPatientSex("男");
            patientList.setPatientBirthday(new Date(2001+i,2+i,14+i));
            patientList.setDoctor("厉害");
            patientList.setRoom("眼科");
            patientList.setCost(2.5);
            patientLists.add(patientList);
        }
        PatientJson patientJson = new PatientJson();
        patientJson.setCode(0);
        patientJson.setCount(patientLists.size());
        int onePageNumber = pageTemp*limitTemp;
        if (onePageNumber > patientLists.size()){
    
    
            onePageNumber = patientLists.size();
        }
        patientJson.setData(patientLists.subList((pageTemp-1)*limitTemp,onePageNumber));
        return patientJson;
    }

Here is the temporary data I designed, if you get the data of the database, the same is true. You can use the following statement
"select * from table limit ((page - 1)*limit), limit;".

Guess you like

Origin blog.csdn.net/xlk_1996/article/details/103693069