My domain has and Date field updated, that I want to search by
@Column(name = "updated")
Date updated;
I have a Java Date object representing a day, that's passed in by my endpoint's controller.
Date day;
and a crudrepository representing my data
public interface DataRepository extends CrudRepository<Data, Long> {
List<Data> findByLastUpdatedInDate(Date date);
}
Obviously the above method doesn't work, but is there something similar? Or am I going to have to do a find between then manually search for the last entry?
Edit: Here's how I get day; dateString is passed in by the controller.
SimpleDateFormat dateFormatIn = new SimpleDateFormat("yyyy-MM-dd");
Date day = dateFormatIn.parse(dateString);
You're almost there. The slight tweak would be this if I read the documentation correctly:
Data data = dataRepository.findTopByUpdatedBetweenOrderByUpdatedDesc(start, stop);
Source: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.limit-query-result
You can annotatw your method with @Query annotation and write HQL query
@Query("select d from Data d where d.updated= :date")
List<Data> findByLastUpdatedInDate(@Param("date") Date date);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With