我在通过使用 spring 数据的日期恢复对象时遇到问题,问题是对象返回为 null,尽管该对象不为 null 谢谢你回复我请 诚挚的
@Repository
public interface ProspectStatistiqueRepository extends JpaRepository<ProspectStatique, Long> {
@Query("select p from ProspectStatique p where p.date_consultation =:date_consultation")
public ProspectStatique getProspectCountByDate(@Param("date_consultation") Date date_consultation);
}
@Autowired
ProspectStatistiqueRepository prospectStatistiqueRepository;
@GetMapping("/products")
public ProductStatique findProductNumberBydate(@RequestParam String date) throws CustomerException, ParseException {
DateFormat format = new SimpleDateFormat("MMMM d, yyyy 'at' hh:mm a", Locale.ENGLISH);
Date dateConvert = format.parse(date);
System.out.println("date param " + date);
System.out.println("dateConvert variable" + dateConvert);
ProductStatique pp = productStatiqueService.getProductCount(dateConvert);
return pp;
}
最佳答案
您使用了JpaRepository,因此您可以使用“Between”、“After”和“Before”来处理日期:
@Repository
public interface ProspectStatistiqueRepository extends JpaRepository<ProspectStatique, Long> {
//1-Between
public List<ProspectStatique> findByDate_consultationBetween(Date date1,Date date2);
//2-After
public List<ProspectStatique> findByDate_consultationAfter(Date date);
//3-Befor
public List<ProspectStatique> findByDate_consultationBefore(Date date);
}
更多信息可以查看spring doc http://docs.spring.io/spring-data/jpa/docs/1.3.4.RELEASE/reference/html/jpa.repositories.html
关于java - 通过带有 Spring 数据的日期进行对象恢复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43468411/