0
I can use findById
in the controller but wanted to know how to create a findByQualquer
to another class property.
follows the code:
Model:
package com.leonardo.pokedex.model;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Objects;
@Document
public class Pokemon{
@Id
private String id;
private String nome;
private String categoria;
private String habilidade;
private Double peso;
public Pokemon() {
super();
}
public Pokemon(String id, String nome, String categoria, String habilidade, Double peso) {
this.id = id;
this.nome = nome;
this.categoria = categoria;
this.habilidade = habilidade;
this.peso = peso;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCategoria() {
return categoria;
}
public void setCategoria(String categoria) {
this.categoria = categoria;
}
public String getHabilidade() {
return habilidade;
}
public void setHabilidade(String habilidade) {
this.habilidade = habilidade;
}
public Double getPeso() {
return peso;
}
public void setPeso(Double peso) {
this.peso = peso;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pokemon pokemon = (Pokemon) o;
return Objects.equals(id, pokemon.id) &&
Objects.equals(nome, pokemon.nome) &&
Objects.equals(categoria, pokemon.categoria) &&
Objects.equals(habilidade, pokemon.habilidade) &&
Objects.equals(peso, pokemon.peso);
}
@Override
public int hashCode() {
return Objects.hash(id, nome, categoria, habilidade, peso);
}
@Override
public String toString() {
return "Pokemon{" +
"id='" + id + '\'' +
", nome='" + nome + '\'' +
", categoria='" + categoria + '\'' +
", habilidade='" + habilidade + '\'' +
", peso=" + peso +
'}';
}
}
Repository:
package com.leonardo.pokedex.repository;
import com.leonardo.pokedex.model.Pokemon;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
public interface PokemonRepository extends ReactiveMongoRepository <Pokemon, String>{
}
Dear Leonardo I recommend that in the future simplify the question to the problem in focus, it is not necessary to add everything, the ideal is to create a minimal functional example or then explain exactly where you need something to focus on this part, that in your case it is Repository that you needed a customized method. I edited the question this time to see if it helps you understand how to ask future questions, I hope the answer will help you, and the question will be useful to you.
– Guilherme Nascimento