how to display database value to datatable in spring project

how to display database value to datatable in spring project

sanjay1095sanjay1095 Posts: 1Questions: 1Answers: 0

i am working on spring project and i want the data which is fetch from database in DAO class to coem to controller class and then pass to jsp where these record will be displayed in datatables.
so i am receiving the data in a list in controller class which i am converting in json string using
    
@RequestMapping(value = "/", method = RequestMethod.GET)
    public String home(Locale locale, Model model) throws JsonGenerationException, JsonMappingException, IOException {
        logger.info("Welcome home! The client locale is {}.", locale);
        LoadDataService dataService = new LoadDataService();
        ObjectMapper mapper = new ObjectMapper();
        model.addAttribute("employeeList", mapper.writeValueAsString(dataService.getEmployeeList()));
        return "home";
    }

the jsp code written is:

<html>
<body>

 
Name Desgination Salary Country

</body>
</html>

$(document).ready(function(){ var data =eval('${employeeList}'); var table = $('#example').DataTable( { "aaData": data, "aoColumns": [ { "mData": "name"}, { "mData": "desgination"}, { "mData": "salary"}, { "mData": "country"} ] }); });

But the output i am getting is just the header of the table
please let me know how should i approach further.

js and css used used is:
jquery-1.12.1.min.js
jquery.dataTables.js
jquery.dataTables.css
jquery.dataTables.min.css

Sign In or Register to comment.