简体   繁体   中英

How to converted dataTable from request Spring Boot

i'm learning programming and want use DataTables and i have a problem. I don't know how to converted records...

I have code in spring boot

@RequestMapping(path="/seriess", method=RequestMethod.GET)
public Page<SeriesDao> showSeries(@RequestParam(defaultValue="0") int page)
{
    Page<SeriesDao> sss = seriesRepository.findAll(new PageRequest(page, 20));

    return sss;
}
@RequestMapping("/showSeries")
public ModelAndView model(){
    ModelAndView model = new ModelAndView("showSeries");
    return model;
}

Next I have json when i go to localhost:8080/seriess, i didn't copy all result (20)

{"content":[{"id":41,"name":"Average Weekly Earnings of All Employees: Total Private in Corpus Christi, TX (MSA)","file":"SMU48185800500000011.csv","cassid":"1d2e556b-031e-4c6f-aec4-981c4e907324","categoryid":3,"datefrom":"2006-12-31","dateto":"2016-09-30","frequency":5,"markers":null,"unit":"$ per Week","feed":"Macroeconomic_And_Major_Markets","createdate":1476567529000,"changedate":1483919401000}........and next 19 records ] "last":false,"totalPages":25,"totalElements":488,"size":20,"number":0,"sort":null,"first":true,"numberOfElements":20}

This is my java script code. I have to correct convert this data from url, but i don't know how...

$(document).ready( function () {
$('#dataTable').DataTable({
    "processing": true,
    "serverSide": true,
    "ajax": {
        "url": "seriess",
        "dataSrc" : ""
         }
    },
        "columns": [
            { "data": "id"},
            { "data": "name" },
            { "data": "file" },
            { "data": "cassid" },
            { "data": "categoryid" },
            { "data": "datefrom" },
            { "data": "dateto" },
            { "data": "frequency" },
            { "data": "markers" },
            { "data": "unit" },
            { "data": "feed" },
            { "data": "createdate" },
            { "data": "changedate" }
        ]
 })});

Change

"ajax": {
        "url": "seriess",
        "dataSrc" : ""
         }
    }

to

"ajax": {
        "url": "/seriess",
        "dataSrc" : "content"
         }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM