首页 文章

得到空洞的回答Mongodb

提问于
浏览
0

嗨,我有一些问题与MongoDb我有一个CRUD,这是我正在使用的代码

首先是POJO:

@Data
@Document(collection = "Informacion")
public class Informacion {

//Declaration code

public Informacion(Pais pais, Date fechaCreacion, String nombre, Boolean sexo,
                   Date fechaNacimiento, List<Preferencias> preferencias, String numTelefono, String usuario,
                   List<RedesSociales> redes, String contraseniaTW, String contraseniaFB, String contraseniaIG,
                   Grupo grupo, String paqChip, String email, String contraseniaMail, String fuente,
                   Date fechaRecarga) {
    this.pais = pais;
    this.fechaCreacion = fechaCreacion;
    this.nombre = nombre;
    this.sexo = sexo;
    this.fechaNacimiento = fechaNacimiento;
    this.preferencias = preferencias;
    this.numTelefono = numTelefono;
    this.usuario = usuario;
    this.redes = redes;
    this.contraseniaTW = contraseniaTW;
    this.contraseniaFB = contraseniaFB;
    this.contraseniaIG = contraseniaIG;
    this.grupo = grupo;
    this.paqChip = paqChip;
    this.email = email;
    this.contraseniaMail = contraseniaMail;
    this.fuente = fuente;
    this.fechaRecarga = fechaRecarga;
}

}

现在DAO:

@Repository
public interface informacionRepo extends MongoRepository<Informacion,String> {
     Informacion findByIdInformacion(String id);
}

和控制器:

@RestController
@RequestMapping("/Informacion")
public class InformacionControlador {
@Autowired
private informacionRepo informacioRepo;

public InformacionControlador(informacionRepo informacioRepo) {
    this.informacioRepo = informacioRepo;
}


@GetMapping("/Listar")
public List<Informacion> getAll(){
    List<Informacion> info = this.informacioRepo.findAll();
    System.out.println(info.isEmpty());
    return info;
}


@PutMapping
public void insert(@RequestBody Informacion informacion){
    this.informacioRepo.insert(informacion);
}


public void update(@RequestBody Informacion informacion){
    this.informacioRepo.save(informacion);
}


@DeleteMapping("/Listar/{id}")
public void delete(@PathVariable("id") String id){
    this.informacioRepo.deleteById(id);
}

@GetMapping("/Listar/{id}")
public Informacion getById(@PathVariable("id") String id){
    Informacion info =  this.informacioRepo.findByIdInformacion(id);
    return info;
}
}

我使用POSTMAN测试上面的方法,但我得到空的答案,数据已经在数据库上设置,即时通讯使用方法调用播种机填充数据也是用robo mongo检查它,数据在那里,但仍然得到空答案当我尝试插入方法时,我得到403错误 . 谢谢你的帮助This is the answer seen from the web browser

1 回答

  • 0

    问题是我使用来自lombok的注释@Data,但我没有在IDE中启用注释处理只是启用它并且工作:D

相关问题