通过带有弹簧数据的日期进行对象恢复 [英] Object Recovery via a date with spring data

查看:79
本文介绍了通过带有弹簧数据的日期进行对象恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过spring数据工作时通过日期恢复对象时遇到问题,尽管该对象不为null,但该对象返回的结果为null 谢谢你给我答复 亲切地

I have a problem recovering an object via a date I work with spring data the problem is that the object returns is null despite this object is not null Thank you for reply me please cordially

@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 ,因此您可以使用介于",之后"和之前"来处理日期:

you used JpaRepository so you can use "Between","After" and "Before" to deal with date :

@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

for more information you can see spring doc http://docs.spring.io/spring-data/jpa/docs/1.3.4.RELEASE/reference/html/jpa.repositories.html

这篇关于通过带有弹簧数据的日期进行对象恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆