<bdo id='KdDJt'></bdo><ul id='KdDJt'></ul>
        <tfoot id='KdDJt'></tfoot>
        <i id='KdDJt'><tr id='KdDJt'><dt id='KdDJt'><q id='KdDJt'><span id='KdDJt'><b id='KdDJt'><form id='KdDJt'><ins id='KdDJt'></ins><ul id='KdDJt'></ul><sub id='KdDJt'></sub></form><legend id='KdDJt'></legend><bdo id='KdDJt'><pre id='KdDJt'><center id='KdDJt'></center></pre></bdo></b><th id='KdDJt'></th></span></q></dt></tr></i><div id='KdDJt'><tfoot id='KdDJt'></tfoot><dl id='KdDJt'><fieldset id='KdDJt'></fieldset></dl></div>
        <legend id='KdDJt'><style id='KdDJt'><dir id='KdDJt'><q id='KdDJt'></q></dir></style></legend>
      1. <small id='KdDJt'></small><noframes id='KdDJt'>

        如何使用 LocalDate 查询 LocalDateTime?

        How to query LocalDateTime with LocalDate?(如何使用 LocalDate 查询 LocalDateTime?)

              <tbody id='6kZn1'></tbody>

            <small id='6kZn1'></small><noframes id='6kZn1'>

            <tfoot id='6kZn1'></tfoot>
              <legend id='6kZn1'><style id='6kZn1'><dir id='6kZn1'><q id='6kZn1'></q></dir></style></legend>
              <i id='6kZn1'><tr id='6kZn1'><dt id='6kZn1'><q id='6kZn1'><span id='6kZn1'><b id='6kZn1'><form id='6kZn1'><ins id='6kZn1'></ins><ul id='6kZn1'></ul><sub id='6kZn1'></sub></form><legend id='6kZn1'></legend><bdo id='6kZn1'><pre id='6kZn1'><center id='6kZn1'></center></pre></bdo></b><th id='6kZn1'></th></span></q></dt></tr></i><div id='6kZn1'><tfoot id='6kZn1'></tfoot><dl id='6kZn1'><fieldset id='6kZn1'></fieldset></dl></div>
                  <bdo id='6kZn1'></bdo><ul id='6kZn1'></ul>
                  本文介绍了如何使用 LocalDate 查询 LocalDateTime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个包含 java.time.LocalDateTime 类型属性的类.

                  I've got a class which contains an atttribute of java.time.LocalDateTime type.

                  public class MyClass{
                      // ...
                      private LocalDateTime fecha;
                      // ...
                  }
                  

                  我正在使用 Spring Data 存储库.我想要完成的是根据日期查询实体:

                  I'm using Spring Data repositories. What I want to accomplish is to query entities according to a date:

                  @Service
                  public interface IRepository extends CrudRepository<MyClass, UUID> {
                      // ...
                      public void deleteByFecha(LocalDate fecha);
                      // ...
                  }
                  

                  但这不起作用,因为抛出了异常:

                  But this does not work, as an exception is thrown:

                  org.springframework.dao.InvalidDataAccessApiUsageException: 参数值 [2016-10-05] 与预期类型不匹配 [java.time.LocalDateTime (n/a)];

                  org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [2016-10-05] did not match expected type [java.time.LocalDateTime (n/a)];

                  所以问题是如何通过 fecha 查询数据库中的 MyClass 但使用 LocalDate?

                  So the question is how can I query MyClass in database by fecha but with a LocalDate?

                  编辑万一有人遇到同样的问题,我想出了一个解决方案:修改存储库的方法,使其如下所示:

                  EDIT Just in case somebody faces the same issue, I've come up with one solution: modify the Repository's method so that it looks as follows:

                  import org.springframework.transaction.annotation.Transactional;
                  import org.springframework.data.jpa.repository.Modifying;
                  import org.springframework.data.jpa.repository.Query;
                  // ...
                  
                  @Service
                  public interface IRepository extends CrudRepository<MyClass, UUID> {
                  
                      @Transactional
                      @Modifying
                      @Query("DELETE FROM MyClass mtc WHERE YEAR(mtc.fecha)=?1 AND MONTH(mtc.fecha)=?2 AND DAY(mtc.fecha)=?3")
                      public void deleteByFecha(Integer year, Integer month, Integer day);
                  
                  }
                  

                  推荐答案

                  试试这个(未测试):

                  public interface IRepository extends CrudRepository<MyClass, UUID> {
                      // ...
                      default void delByFecha(LocalDate fecha) {
                  
                          deleteByFechaBetween(fecha.atStartOfDay(), fecha.plusDays(1).atStartOfDay());
                  
                      }
                  
                      void deleteByFechaBetween(LocalDateTime from, LocalDateTime to);
                      // ...
                  }
                  

                  这篇关于如何使用 LocalDate 查询 LocalDateTime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                  1. <legend id='h45BQ'><style id='h45BQ'><dir id='h45BQ'><q id='h45BQ'></q></dir></style></legend>

                      <bdo id='h45BQ'></bdo><ul id='h45BQ'></ul>

                      <small id='h45BQ'></small><noframes id='h45BQ'>

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

                          • <tfoot id='h45BQ'></tfoot>