我试图在本机查询中传递存储过程的参数, 网址为http://localhost:3025/bbr?BatteryBankID=1&fromDate=2017-01-10&toDate=2017-12-25
已存储的程序
Alter PROCEDURE [dbo].[Sample]
@BatteryBankID Int,
@fromDate DateTime,
@toDate DateTime
AS BEGIN
select
bbr.StrVoltage,bbr.ChrgCurr
from BatteryBankReadings bbr
where bbr.BatteryBankID = @BatteryBankID
and ReadTime between @fromDate and @toDate
END
GO
REPOSITORY
public interface SampleRepo extends CrudRepository<BatteryBankReadings, Integer> {
@Query(value = "{call Sample :BatteryBankID, ':fromDate', ':toDate'}", nativeQuery = true)
public List<BatteryBankReadings> samp(@Param("BatteryBankID") int BatteryBankID, @Param("fromDate") String fromDate,@Param("toDate") String toDate);
}
例外:
java.lang.IllegalArgumentException: Parameter with that name [fromDate] did not exist
at org.hibernate.jpa.spi.BaseQueryImpl.findParameterRegistration(BaseQueryImpl.java:487) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.jpa.spi.BaseQueryImpl.setParameter(BaseQueryImpl.java:638) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:163) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:32) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:139) ~[spring-data-jpa-1.11.9.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.StringQueryParameterBinder.bind(StringQueryParameterBinder.java:61) ~[spring-data-jpa-1.11.9.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:101) ~[spring-data-jpa-1.11.9.RELEASE.jar:na]
...........SO ON
请帮助我,提前致谢 - :)
答案 0 :(得分:0)
通过将参数保持在括号内,
public interface SampleRepo extends CrudRepository<BatteryBankReadings, Integer> {
@Query(value = "{call Sample (:BatteryBankID, :fromDate, :toDate)}", nativeQuery = true)
public List<BatteryBankReadings> samp(@Param("BatteryBankID") int BatteryBankID, @Param("fromDate") String fromDate,@Param("toDate") String toDate);
}