You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesión a prueba de IA

Antes: $249

Currency
$209
Suscríbete

Termina en:

0 Días
1 Hrs
46 Min
30 Seg

Query Methods: And, Or, True, IgnoreCase, OrderBy

11/25
Resources

Contributions 8

Questions 1

Sort by:

Want to see more contributions, questions and answers from the community?

Buenísimo todo lo que te facilita las búsquedas el JPA, por aquí les dejo la documentación donde están todos los atajos que se pueden usar para combinarlos y crear Querys:

https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation

Mi implementacion del metodo getByName, es una alternativa, espero les aporte algo:

@GetMapping(params = "name")
public ResponseEntity<Pizza> getByName(@RequestParam("name") String name) {
    return ResponseEntity.ok(pizzaService.getByName(name));
}

Se consumiria de la siguiente forma:

GET http://localhost:8080/api/pizzas?name=Margherita
Content-Type: application/json

Para nombres con espacios se usa el caracter especial “%20” que representa un espacio

GET http://localhost:8080/api/pizzas?name=Avocado%20Festival
Content-Type: application/json

Comparto otros metodos derivados

@Repository
public interface EmployeeRepository extends CrudRepository<EmployeeEntity, Long> {

public List<EmployeeEntity> findByCommissionPctIsNull();
	
	public List<EmployeeEntity> findByCommissionPctIsNotNull();
	
	public List<EmployeeEntity> findByFirstNameStartingWith(String inicio);
	
	public List<EmployeeEntity> findByLastNameEndingWith(String fin);
	
	public List<EmployeeEntity> findByFirstNameContaining(String cadena);
	
	//public List<EmployeeEntity> findByFirstNameLike(String like);
	
	public List<EmployeeEntity> findByLastNameLike(String like);
	
	public List<EmployeeEntity> findByFirstNameStartingWithAndLastNameLike(String inicio, String like);
	
	public List<EmployeeEntity> findByFirstNameStartingWithOrLastNameStartingWith(String inicioFirstName, String inicioLastName);
	
	public List<EmployeeEntity> findBySalaryLessThan(Double salary);//<
	public List<EmployeeEntity> findBySalaryLessThanEqual(Double salary); //<=
	
	public List<EmployeeEntity> findBySalaryGreaterThan(Double salary);//>
	
	public List<EmployeeEntity> findBySalaryBetween(Double min, Double max);
	
	//public List<EmployeeEntity> findByJobIdIn(List<String> jobIds);
	
	public List<EmployeeEntity> findByHireDateAfter(LocalDate hireDateAfter);
	
	public List<EmployeeEntity> findByHireDateBefore(LocalDate hireDateBefore);
	
	public List<EmployeeEntity> findByOrderBySalary();//Asc
	public List<EmployeeEntity> findByOrderBySalaryAsc();//Asc
	public List<EmployeeEntity> findByOrderBySalaryDesc();//Desc
	
	public List<EmployeeEntity> findByFirstNameLike(String expresion);
	
	public List<EmployeeEntity> findByFirstNameEndingWithAndLastNameEndingWith(String first, String last);
	public List<EmployeeEntity> findByFirstNameStartingWithAndLastNameEndingWith(String first, String last);
	
	
	//public List<EmployeeEntity> findByDepartmentIdInAndSalaryGreaterThan(List<Integer> depId, Double salary);
//	public List<EmployeeEntity> findByDepartmentIdIn(List<Integer> depId);
	
	//public List<EmployeeEntity> findByHireDateAfterOrderByHireDateAsc(LocalDate hireDateAfter);
	//public List<EmployeeEntity> findByHireDateAfter(LocalDate hireDateAfter);
	
	public  List<EmployeeEntity> findByCommissionPctIsNotNullAndSalaryBetweenOrderBySalaryDesc(Double min, Double max);
	
	
	public List<EmployeeEntity> findByOrderByFirstNameAscLastNameDesc();
	
	public List<EmployeeEntity> findByCommissionPctIsNotNullAndSalaryBetween(Double min, Double max);
	
	public List<EmployeeEntity> findByCommissionPctIsNullAndSalaryGreaterThanOrderBySalaryDesc(Double salaryMin);

Para todos aquello que quieran hacer una búsqueda donde el criterio sea la(s) letra(s) por las que inicia el nombre, les dejo la consulta.

Una maravilla Spring Data JPA con esto de query methods

Bonita clase, se entendió muy bien. Sigue así Alejandr!

Aquí esta la lista de palabras claves admitidas por JPA y su traducción a SQL <https://docs.spring.io/spring-data/jpa/reference/jpa/query-methods.html#jpa.query-methods.query-creation>