Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
@如果参数位于Spring框架中的单引号内,则查询无法识别这些参数_Spring_Postgresql_Spring Boot_Kotlin_Spring Data - Fatal编程技术网

@如果参数位于Spring框架中的单引号内,则查询无法识别这些参数

@如果参数位于Spring框架中的单引号内,则查询无法识别这些参数,spring,postgresql,spring-boot,kotlin,spring-data,Spring,Postgresql,Spring Boot,Kotlin,Spring Data,我对@Query中的Spring数据有一个大问题 我有以下疑问: SELECT created_at::DATE "date", count(*) FROM absence WHERE created_at::DATE between '2018-05-27' AND '2018-05-31' GROUP BY created_at::DATE; 此查询在postgres中工作,现在在spring中使用它没有任何问题: @Query("SELECT created_at\\:\\:DAT

我对@Query中的Spring数据有一个大问题

我有以下疑问:

SELECT created_at::DATE "date",
count(*)
FROM
absence
WHERE
created_at::DATE between '2018-05-27' AND  '2018-05-31'
GROUP BY created_at::DATE;
此查询在postgres中工作,现在在spring中使用它没有任何问题:

  @Query("SELECT created_at\\:\\:DATE \"date\",count(*) FROM absence " +
            "WHERE created_at\\:\\:DATE between '?1' AND '?2' " +
            "GROUP created_at\\:\\:DATE", nativeQuery = true)
    fun getAbsenceCount(beginDate: String,endDate: String): List<AbsenceCount>
@Query(“选择在\\:\:日期\“DATE\”,从缺勤开始计数(*)+
“创建位置\\:\ \:日期介于“?1”和“?2”之间”+
“在\\:\\:日期创建的组”,nativeQuery=true)
有趣的GetAbscenceCount(beginDate:String,endDate:String):列出并解决这个问题。

我不知道这是有意的还是春天的bug。

试着简单地使用经典的SQL函数:

@Query(value = "" + 
    "select " +
    "  cast(a.created_at as date) as createdAt, " +
    "  count(*) as quantity " + 
    "from " + 
    "  absence a " + 
    "where " + 
    "  cast(a.created_at as date) between ?1 and ?2 " + 
    "group " + 
    "  cast(a.created_at as date)" + 
    "", nativeQuery = true)
fun getAbsenceCount(beginDate: String, endDate: String): List<AbsenceCount>

您是否尝试过在“?1”和“?2”之间不加引号?它是这样工作的还是显示了一些不同的错误?@KuldeepSidhu是的,我做了,但单引号是必要的;这是我得到的错误:
org.postgresql.util.psqleexception:error:syntax error位于或接近“created_at”位置:132
是否尝试在不使用任何强制转换的情况下使用查询(“::date”等)?那你为什么要用它呢???@Cepr0这是postgres的施展方式。我使用这个查询是因为它是我问题的解决方案。我还使用postgres,并且只对jsonb字段使用强制转换。那么您是否尝试从此查询中排除强制转换?仍然?1和?2不在单引号内?此查询将无法工作。
public interface AbsenceCount {
    LocalDate getCreatedAt();
    Long getQuantity();
}