• <i id='8pZc7'><tr id='8pZc7'><dt id='8pZc7'><q id='8pZc7'><span id='8pZc7'><b id='8pZc7'><form id='8pZc7'><ins id='8pZc7'></ins><ul id='8pZc7'></ul><sub id='8pZc7'></sub></form><legend id='8pZc7'></legend><bdo id='8pZc7'><pre id='8pZc7'><center id='8pZc7'></center></pre></bdo></b><th id='8pZc7'></th></span></q></dt></tr></i><div id='8pZc7'><tfoot id='8pZc7'></tfoot><dl id='8pZc7'><fieldset id='8pZc7'></fieldset></dl></div>

    <tfoot id='8pZc7'></tfoot>

    • <bdo id='8pZc7'></bdo><ul id='8pZc7'></ul>

      1. <small id='8pZc7'></small><noframes id='8pZc7'>

        <legend id='8pZc7'><style id='8pZc7'><dir id='8pZc7'><q id='8pZc7'></q></dir></style></legend>

        Spring数据查询日期时间只有日期

        时间:2024-08-24

        <tfoot id='3rggk'></tfoot>

      2. <legend id='3rggk'><style id='3rggk'><dir id='3rggk'><q id='3rggk'></q></dir></style></legend>

            • <small id='3rggk'></small><noframes id='3rggk'>

                <tbody id='3rggk'></tbody>

                • <bdo id='3rggk'></bdo><ul id='3rggk'></ul>
                  <i id='3rggk'><tr id='3rggk'><dt id='3rggk'><q id='3rggk'><span id='3rggk'><b id='3rggk'><form id='3rggk'><ins id='3rggk'></ins><ul id='3rggk'></ul><sub id='3rggk'></sub></form><legend id='3rggk'></legend><bdo id='3rggk'><pre id='3rggk'><center id='3rggk'></center></pre></bdo></b><th id='3rggk'></th></span></q></dt></tr></i><div id='3rggk'><tfoot id='3rggk'></tfoot><dl id='3rggk'><fieldset id='3rggk'></fieldset></dl></div>
                  本文介绍了Spring数据查询日期时间只有日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有这个数据模型

                  public class CustomerModel{
                  
                    @Column
                    @Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
                    private DateTime membershipDate;
                    //Other properties and getters
                  }
                  

                  还有下面的回购

                  public interface CustomerRepo  extends Repository<CustomerModel, Long>{}
                  

                  我想做的是.检索给定日期的所有用户,例如(2013 年 8 月 1 日加入的成员),但问题是在我的数据库上,membershipDate 有时间.如何忽略时间并检索给定日期的所有用户?

                  What I want to do is. Retrieve all users on a given date eg(Members that Joined in August 1 2013) however the problem is that on my DB the membershipDate has a time with it. how can I ignore the time and retrieve all users on a given date?

                  推荐答案

                  不幸的是,使用 JodaTime 的唯一方法是使用 Between 关键字并使用两个 DateTime 实例一天.

                  Unfortunately with JodaTime the only way around this is using the Between keyword and use two DateTime instances making up the day.

                  interface CustomerRepo extends Repository<CustomerModel, Long>{
                  
                    List<CustomerModel> findByMemberShipDateBetween(DateTime start, DateTime end);
                  }
                  

                  如果您的域模型在内部使用 Java Date,您可以使用这种样式:

                  If your domain model used Java Dates internally you could've used this style:

                  interface CustomerRepo extends Repository<CustomerModel, Long>{
                  
                    List<CustomerModel> findByMemberShipDate(@Temporal(TemporalType.DATE) Date date);
                  }
                  

                  @Temporal 注释不是自定义 Spring Data JPA 注释,因为当前不允许在参数上使用普通 JPA 注释.不幸的是,这只适用于 Java Date 的原因是当前 JPAPI 的限制.Query 上的 setParameter(…) 方法只为 Date 类型的参数采用 TemporalType.我们可以尝试在参数绑定上转换 JodaTime 对象,但我猜持久性提供者会因为类型不匹配而拒绝它(Date VS. DateTime).

                  Not the @Temporal annotation is a custom Spring Data JPA one as the plain JPA one is currently not allowed on parameters. The reason that this only works with Java Dates unfortunately is a limitation of the current JPAPIs. The setParameter(…) method on Query only takes a TemporalType for parameters of type Date. We could try converting the JodaTime objects on parameter binding but I guess the persistence providers will reject that due to the type mismatch then (Date VS. DateTime).

                  这篇关于Spring数据查询日期时间只有日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Spring数据保存与saveAll性能 下一篇:为什么没有使用 Spring Data JPA 设置版本属性?

                  相关文章

                  <i id='7mUoX'><tr id='7mUoX'><dt id='7mUoX'><q id='7mUoX'><span id='7mUoX'><b id='7mUoX'><form id='7mUoX'><ins id='7mUoX'></ins><ul id='7mUoX'></ul><sub id='7mUoX'></sub></form><legend id='7mUoX'></legend><bdo id='7mUoX'><pre id='7mUoX'><center id='7mUoX'></center></pre></bdo></b><th id='7mUoX'></th></span></q></dt></tr></i><div id='7mUoX'><tfoot id='7mUoX'></tfoot><dl id='7mUoX'><fieldset id='7mUoX'></fieldset></dl></div>

                  <small id='7mUoX'></small><noframes id='7mUoX'>

                      <bdo id='7mUoX'></bdo><ul id='7mUoX'></ul>
                    1. <tfoot id='7mUoX'></tfoot>
                    2. <legend id='7mUoX'><style id='7mUoX'><dir id='7mUoX'><q id='7mUoX'></q></dir></style></legend>