Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81728

Whats wrong with this?

$
0
0

Ok this is mysql database, java using eclipse springboot webapp. Everything works but the data comes back as one big unformatted blob on the jsp page when going to web site localhost:8080/index. I know I am almost there but somethings not 100% correct.I removed the jsp datatable part on the jsp and got the same result, so the page is apparently not seeing that but I dont know why?

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.service.ServiceInterface;

import model.ScraperObject;
@RestController
public class HomeRestController {
    @Autowired
    private ServiceInterface scraperService;

    @RequestMapping(path="/index", method=RequestMethod.GET)
    public List<ScraperObject> getAllNonDectivatedData(){
        List<ScraperObject>  allNonDectivated = scraperService.getAllNonDeactivatedOnes();
        return allNonDectivated;
    }
}

jsp page

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Spring Boot + JPA + Datatables</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
    <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
    <script>$(document).ready( function () {
         var table = $('#scrapedTable').DataTable({
                "sAjaxSource": "/scrapedData",
                "order": [[ 0, "asc" ]],
                "columns": [
                      { "data": "price"},
                      { "data": "description" },
                      { "data": "url" }
                ]
         })
    });
    </script>
</head>
<body>
    <h1>Employees Table</h1>
    <table id="scrapedTable" class="display">
      
       <!-- Header Table -->
       <thead>
            <tr>
                <th>Price</th>
                <th>Description</th>
                <th>Url</th>
            </tr>
        </thead>
        <!-- Footer Table -->
        <tfoot>
            <tr>
                <th>Price</th>
                <th>Description</th>
                <th>Url</th>
            </tr>
        </tfoot>
    </table>

</body>

</html>

pojo

package model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class ScraperObject {
    
    //private long id;
    //private String name;

    
    //private boolean active;
    @Id
    @GeneratedValue
    @Column(name="url")
    private String url;
    @Column(name="description")
    private String description;
    @Column(name="price")
    private String price;
    //public String scrapedData;
//  public String date;
//  public String location;
//  public UUID guid;
//  public String picture;
//  public boolean deactivatedBoolean;

    public void setUrl(String aUrl) {
        url =aUrl;
    }
    public String getUrl() {
        return url;
    }

    
        
    public void setPrice(String aPrice) {
        price = aPrice;
    }
    public String getPrice() {
        return price;
    }
    public void setDescription(String aDescription) {
        description = aDescription;
    }
    public String getDescription() {
        return description;
    }
    
    /*
     * 
     * public String getPicture() { 
        return picture;
    }
    public void setPicture(String aPict) {
        picture = aPict;
    }
    public boolean getDeactivated() {
        return deactivatedBoolean;
    }
    public void setDeactivated(boolean aBoolean) {
        deactivatedBoolean = aBoolean;
    }
    public UUID getGuid() {
        return guid;
    }
    public String getLocation(String aLocation) {
        return location;
    }
    public String  getDate() {
        return date;
    }
    public String getLocation() { 
        return location;
    }
    public void setLocation(String aLocation) {
        location = aLocation;
    }
    public void setGuid(UUID aGuid) {
        guid = aGuid;
    }
    public void setDate(String aDate) {
        date = aDate;
    }
    public void setSrappedData(String aScrappedData) {
        scrapedData =aScrappedData;
    }
    public String getScrapedData() {
        return scrapedData;
    }
    */
}


service

package com.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.repository.ScraperMqSQL;

import model.ScraperObject;

@Service("scraperService")
public class ScraperServiceImpl implements ServiceInterface{
    @Autowired
    private ScraperMqSQL repository;

    @Override
    public List<ScraperObject> getAllNonDeactivatedOnes() {
        return repository.getAllNonDeactivated();
    }
}

Viewing all articles
Browse latest Browse all 81728

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>