java - 我有错误检查手册对应的mysql服务器版本
问题描述
存储库:
包 com.apsilabs.meterwebapi.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.apsilabs.meterwebapi.model.ActualsBlockLoad;
import com.apsilabs.meterwebapi.viewmodel.ActualsBlock;
@Repository
public interface ActualsBlockLoadRepository extends JpaRepository<ActualsBlockLoad, Long> {
@Query(nativeQuery=true,value= "SELECT NEW com.apsilabs.meterwebapi.viewmodel.ActualsBlock(CONVERT(hour(rtc), CHAR(50)) as hours,CONVERT(date(rtc), CHAR(50)) as dates,CONVERT(IFNULL(avg(JSON_EXTRACT(JSON_UNQUOTE(data),'$.\\\"1012270255\\\"')),0),CHAR(50)) as voltage) from actuals_block_load group by hours,dates order by dates,hours")
public List<ActualsBlock> getActualsBlockLoad();
}
我有一个错误:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 '.apsilabs.meterwebapi.viewmodel.ActualsBlock(CONVERT(hour(rtc), CHAR(50)) as hou' 附近使用正确的语法
新班级:
package com.apsilabs.meterwebapi.viewmodel;
public class ActualsBlock {
private String hours;
private String dates;
private String voltage;
public String getHours() {
return hours;
}
public void setHours(String hours) {
this.hours = hours;
}
public String getDates() {
return dates;
}
public void setDates(String dates) {
this.dates = dates;
}
public String getVoltage() {
return voltage;
}
public void setVoltage(String voltage) {
this.voltage = voltage;
}
public ActualsBlock(String hours, String dates, String voltage) {
super();
this.hours = hours;
this.dates = dates;
this.voltage = voltage;
}
public ActualsBlock() {
super();
}
}
解决方案
您使用了 nativeQuery=true并且此查询不是本机的。
SELECT NEW com.apsilabs.meterwebapi.viewmodel.ActualsBlock(CONVERT(hour(rtc), CHAR(50)) as hours,CONVERT(date(rtc), CHAR(50)) as dates,CONVERT(IFNULL(avg(JSON_EXTRACT(JSON_UNQUOTE(data),'$.\\\"1012270255\\\"')),0),CHAR(50)) as voltage) from actuals_block_load group by hours,dates order by dates,hours.
为什么您要使用新的 com.apsilabs.meterwebapi.viewmodel.ActualsBlock(CONVERT.... 如果是本机查询
推荐阅读
- audio - 音频分析和频率峰值
- python - 使用flask rest API将用户添加到Mysql数据库时如何获取JSON结果
- ios - 为什么我不能在我的 Objective-C 代码中使用我的 swift 文件?
- android - 为什么我的基础 Realm 实例上会出现 NPE?
- c++ - 如何从透明度计算不透明度?
- javascript - 获取 REST 请求的 XML 和实体
- html - 调整宽度
- 适合
- 使用内联
- 适合
- python - 使用 pandas 读取 csv 文件并显示带有排序日期/时间的单元格值
- ios - 使用 GCD 实现线程池
- python - 如何在流程结束之前生成和使用随机数?