将消耗的API插入JPA时发生异常,无法识别

时间:2018-09-24 21:45:16

标签: spring jpa

我是Spring Boot和JPA的新手,我正在做一个简单的项目,其中包括接收json字符串并将其转换为模型,然后将其插入JPA。

我正在使用的

API ... https://www.ipvigilante.com/

类...模型

//history.js
import createMemoryHistory from "history/createMemoryHistory";
const history = createMemoryHistory();
export default history;

//App.js
import history from './history/history';
...
<Router>
   <Route
      path={'/'}
      render={(props) => <Component {...props}/>}
   />
</Router>

//component.js
...
function handleClick(history) {
    history.push('somePath'); // this updates my url to be url.com/somePath
} 
return (<Button onClick={() => handleClick(this.props.history)}>);

然后我将其按如下方式分配给每个班级

import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;


@Entity
public class Cliente {

//Classe cliente (model)
@Id
private String id;
@Column(name="name")
private String name;
@Column(name="idade")
private int idade;
private Ipvigilante ip;

public Cliente() {
    super();
}
public Cliente(Ipvigilante ip,String id ,String name, int idade) {
    super();
    this.name = name;
    this.idade = idade;
    this.id =  id;
    this.ip = ip;
}


public Ipvigilante getIp() {
    return ip;
}
public void setIp(Ipvigilante ip) {
    this.ip = ip;
}
public String getId() {
    return id;
}
public void setId(String id) {
    this.id = id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public int getIdade() {
    return idade;
}
public void setIdade(int idade) {
    this.idade = idade;
}
}

还有剩下的数据类

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown=true)
public class Ipvigilante  {

private String status;
private Data data;

public String getStatus() {
    return status;
}
public void setStatus(String status) {
    this.status = status;
}
public Data getData() {
    return data;
}
public void setData(Data data) {
    this.data = data;
}

@Override 
public String toString() {
    return "{" + 
              "status='" + status +'\''
            + ", Data=" + data +
            '}';
}
}

还有例外。...

@JsonIgnoreProperties(ignoreUnknown=true)  
public class Data {

private String ipv4;
private String continent_name;
private String country_name;
private String subdivision_1_name;
private String subdivision_2_name;
private String city_name;
private String latitude;
private String longitude;


public String getIpv4() {
    return ipv4;
}
public void setIpv4(String ipv4) {
    this.ipv4 = ipv4;
}
public String getContinent_name() {
    return continent_name;
}
public void setContinent_name(String continent_name) {
    this.continent_name = continent_name;
}
public String getCountry_name() {
    return country_name;
}
public void setCountry_name(String country_name) {
    this.country_name = country_name;
}
public String getSubdivision_1_name() {
    return subdivision_1_name;
}
public void setSubdivision_1_name(String subdivision_1_name) {
    this.subdivision_1_name = subdivision_1_name;
}
public String getSubdivision_2_name() {
    return subdivision_2_name;
}
public void setSubdivision_2_name(String subdivision_2_name) {
    this.subdivision_2_name = subdivision_2_name;
}
public String getCity_name() {
    return city_name;
}
public void setCity_name(String city_name) {
    this.city_name = city_name;
}
public String getLatitude() {
    return latitude;
}
public void setLatitude(String latitude) {
    this.latitude = latitude;
}
public String getLongitude() {
    return longitude;
}
public void setLongitude(String longitude) {
    this.longitude = longitude;
}

@Override
public String toString() {

    return "Data{" + "ipv4=' " + ipv4 + '\''+
             ",continent_name=" + continent_name + '\''+
             ",country_name=" + country_name + '\'' + 
             "subdivision_1_name=" + subdivision_1_name + '\'' +
             "subdivision_2_name=" + subdivision_2_name + '\'' +
             "city_name=" + city_name + '\'' +
             "latitude=" + latitude + '\'' +
             "longitude=" + longitude + '\''
            + '}';
}
}

0 个答案:

没有答案