我想读取json数据,然后将其保存到我的postgres数据库中,但是我得到了消息:
由于输入结束,没有要映射的内容 在[资料来源:未知;行:1,列:0]
Mi文件是: 实体:Visita.java
package pe.com.carsa.sintec.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.sql.Time;
import java.util.Date;
@Entity
@Table(schema = "cobranzas", name = "tb_visita")
public class Visita {
@Column(name = "motivo", length = 100, nullable = true)
private String motivo;
@Column(name = "pv_codigo")
private int pvCodigo;
@Column(name = "posicion_inicio", length = 25, nullable = true)
private String posicionInicio;
@Column(name = "dni", length = 15, nullable = true)
private String dni;
@Column(name = "efectiva", nullable = true)
private boolean efectiva;
@Column(name = "u_nombre", length = 150, nullable = true)
private String uNombre;
@Column(name = "en_zona_cliente", nullable = true)
private String enZonaCliente;
@Column(name = "pv_cliente", length = 255, nullable = true)
private String pvCliente;
@Column(name = "fecha_hora_fin", nullable = true)
private Date fechaHoraFin;
@Column(name = "duracion", nullable = true)
private Time duracion;
@Column(name = "fecha_hora_inicio", nullable = true)
private Date fechaHoraInicio;
@Id
@Column(name = "id_visita", nullable = true)
private long idVisita;
@Column(name = "en_zona_vendedor", nullable = true)
private boolean enZonaVendedor;
@Column(name = "tiempo_muerto", nullable = true)
private Time tiempoMuerto;
@Column(name = "sin_finalizar", nullable = true)
private boolean sinFinalizar;
@Column(name = "comentario", length = 255, nullable = true)
private String comentario;
public Visita() {
}
getters and setters...
}
VisitaService.java
package pe.com.carsa.sintec.service;
import java.util.List;
public interface VisitaService<Visita> {
public Iterable<Visita> list();
public Iterable<Visita> save(List<Visita> visitas);
}
VisitaServiceImpl.java
package pe.com.carsa.sintec.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pe.com.carsa.sintec.entity.Visita;
import pe.com.carsa.sintec.repository.VisitaRepository;
import java.util.List;
@Service
public class VisitaServiceImpl implements VisitaService<Visita> {
private VisitaRepository visitaRepository;
@Autowired
public VisitaServiceImpl(VisitaRepository visitaRepository) {
this.visitaRepository = visitaRepository;
}
@Override
public Iterable<Visita> list() {
return visitaRepository.findAll();
}
@Override
public Iterable<Visita> save(List<Visita> visitas) {
return visitaRepository.saveAll(visitas);
}
}
VisitaRepository.java
package pe.com.carsa.sintec.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import pe.com.carsa.sintec.entity.Visita;
public interface VisitaRepository extends JpaRepository<Visita, Long> {
}
SintecApplication.java
package pe.com.carsa.sintec;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import pe.com.carsa.sintec.entity.Visita;
import pe.com.carsa.sintec.service.VisitaService;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@SpringBootApplication
public class SintecApplication {
public static void main(String[] args) {
SpringApplication.run(SintecApplication.class, args);
}
@Bean
CommandLineRunner runner(VisitaService visitaService) {
return args -> {
String url = "XXX.YYY.ZZZ.MMM:1234/path/path/site.action?codCuenta=1&codCampana=1&fechaInicio=2018/10/05 00:00:00&fechaFin=2018/10/06 00:00:00&idUsuarioInvoca=1";
ObjectMapper mapper = new ObjectMapper();
TypeReference<List<Visita>> typeReference = new TypeReference<List<Visita>>() {};
InputStream inputStream = typeReference.getClass().getResourceAsStream(url);
try {
List<Visita> visitas = mapper.readValue(inputStream, typeReference);
//List<Visita> visitas = (List<Visita>) mapper.readValue(url, Visita.class);
visitaService.save(visitas);
System.out.println("===SE GUARDO CON EXITO");
} catch (IOException e) {
System.out.println("***ERROR: NO SE PUDO GUARDAR LA DATA");
System.out.println(e.getMessage());
}
};
}
}
这是json数据:
[{"Motivo":"","pv_CODIGO":"1942645","PosicionInicio":"-11.858479,-77.1199","pv_DNI":"76409500","Efectiva":true,"u_Nombre":"OSCAR SANTAMARIA","EnzonaCliente":false,"pv_CLIENTE":"NOMBRE ; EDAD | JHONATHAN GUILLERMO CARRANZA ROJAS ; 21","FechayHoraFin":"2018/10/05 08:15:00","Duracion":"00:00:33","FechayHoraInicio":"2018/10/05 08:14:00","idVisita":470761,"EnzonaVendedor":true,"TiempoMuerto":"00:00:00","SinFinalizar":false,"Comentario":""},{"Motivo":"","pv_CODIGO":"1723903","PosicionInicio":"-11.858643,-77.11976","pv_DNI":"43893067","Efectiva":true,"u_Nombre":"OSCAR SANTAMARIA","EnzonaCliente":false,"pv_CLIENTE":"NOMBRE ; EDAD | LEYDY MARIA PALOMINO JULCA ; 32","FechayHoraFin":"2018/10/05 08:16:00","Duracion":"00:00:22","FechayHoraInicio":"2018/10/05 08:15:00","idVisita":470762,"EnzonaVendedor":true,"TiempoMuerto":"00:00:47","SinFinalizar":false,"Comentario":""},{"Motivo":"","pv_CODIGO":"1912759","PosicionInicio":"-11.85855,-77.1198","pv_DNI":"47600923","Efectiva":true,"u_Nombre":"OSCAR SANTAMARIA","EnzonaCliente":false,"pv_CLIENTE":"NOMBRE ; EDAD | ORALDO IPUSHIMA ARIRAMA ; 36","FechayHoraFin":"2018/10/05 08:17:00","Duracion":"00:00:32","FechayHoraInicio":"2018/10/05 08:16:00","idVisita":470763,"EnzonaVendedor":true,"TiempoMuerto":"00:00:28","SinFinalizar":false,"Comentario":""}]
我不知道该怎么办。