Spring Boot-响应为空

时间:2019-04-02 16:15:30

标签: spring-boot response

API给了我一个空的答案。如果我调试变量,它看起来已满,但是在返回时它变为空,则该表包含数据,我会手工加载它;如果我执行“ SELECT * FROM clients”,它将为我带来这些数据,我不了解是他回来时显示为空

CLASS

package com.gestion.backend.entidades;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;

@Entity
@Table(name="clientes")
@Data
public class Cliente {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column
    private Long id;

    @Column
    private String nombre;

    @Column
    private String apellido;

    @Column
    private String email;

    @Column
    private String localidad;

    @Column
    private String provincia;

    @Column(name="tipo_documento")
    private String tipoDocumento;

    @Column
    private String documento;

    @Column
    private String nacionalidad;

    @Column(name="codigo_postal")
    private String codigoPostal;

    @Column
    private String direccion;

    @Column(name="telefono_fijo")
    private String telefonoFijo;

    @Column
    private String celular;

    @Column(name="telefono_alternativo")
    private String telefonoAlternativo;

    @Column(name="forma_de_pago")
    private String formaDePago;

    @Column
    private String condiciones;


}

控制器

package com.gestion.backend.controllers;

import java.util.List;

import com.gestion.backend.entidades.Cliente;
import com.gestion.backend.services.ClientesService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class ClientesController {

    @Autowired
    ClientesService clientesService;


    // Traigo todos los usuarios
    @GetMapping("/clientes")
    public List<Cliente> getClientes(){
        List<Cliente> clientes = clientesService.getClientes();

        //return clientesService.getClientes();
        return clientes;
    }

    // Traigo un usuario especifico
    @GetMapping("/clientes/{id}")
    public Cliente getClientes(@PathVariable Long id){

        return clientesService.getClientesById(id);
    }



}

服务

package com.gestion.backend.services;

import java.util.List;

import com.gestion.backend.entidades.Cliente;;

public interface ClientesService {

    // Metodos para la clase Clientes
    public List<Cliente> getClientes();

    public Cliente getClientesById(Long id);
}

SERVICE IMPL

package com.gestion.backend.services.implementation;
import com.gestion.backend.dao.ClientesRepository;
import com.gestion.backend.entidades.Cliente;
import com.gestion.backend.services.ClientesService;
import java.util.List;

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

@Service
public class ClientesServiceImpl implements ClientesService {

    @Autowired
    private ClientesRepository clientesRepository;

    public List<Cliente> getClientes(){
        return clientesRepository.findAll();
    }

    public Cliente getClientesById(Long id){
        return clientesRepository.findById(id);
    }

}

存放

package com.gestion.backend.dao;

import java.util.List;
import java.io.Serializable;
import org.springframework.stereotype.Repository;
import com.gestion.backend.entidades.Cliente;
import org.springframework.data.jpa.repository.JpaRepository;

@Repository("clientesRepository")
public interface ClientesRepository  extends JpaRepository<Cliente, Serializable>{

    List<Cliente> findAll();

    Cliente findById(Long id);

    //void softDelete(Integer id);
}

从HIBERNATE选择

Hibernate: select cliente0_.id as id1_0_, cliente0_.apellido as apellido2_0_, cliente0_.celular as celular3_0_, cliente0_.codigo_postal as codigo_p4_0_, cliente0_.condiciones as condicio5_0_, cliente0_.direccion as direccio6_0_, cliente0_.documento as document7_0_, cliente0_.email as email8_0_, cliente0_.forma_de_pago as forma_de9_0_, cliente0_.localidad as localid10_0_, cliente0_.nacionalidad as naciona11_0_, cliente0_.nombre as nombre12_0_, cliente0_.provincia as provinc13_0_, cliente0_.telefono_alternativo as telefon14_0_, cliente0_.telefono_fijo as telefon15_0_, cliente0_.tipo_documento as tipo_do16_0_ from clientes cliente0

有人知道为什么它返回空吗? [{}] 谢谢!!!

0 个答案:

没有答案