Name for parameter binding must not be null or empty! On JDKs < 8, you need to use @Param for named

SpringBoor加 jpa,工作当中出现了如下的错误,

2017-11-23 15:55:37.600 ERROR 11188 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Name for parameter binding must not be null or empty! On JDKs < 8, you need to use @Param for named parameters, on JDK 8 or better, be sure to compile with -parameters.; nested exception is java.lang.IllegalArgumentException: Name for parameter binding must not be null or empty! On JDKs < 8, you need to use @Param for named parameters, on JDK 8 or better, be sure to compile with -parameters.] with root cause

java.lang.IllegalArgumentException: Name for parameter binding must not be null or empty! On JDKs < 8, you need to use @Param for named parameters, on JDK 8 or better, be sure to compile with -parameters.
    at org.springframework.util.Assert.hasText(Assert.java:181)
    at org.springframework.data.jpa.repository.query.StringQuery.getBindingFor(StringQuery.java:105)
    at org.springframework.data.jpa.repository.query.StringQueryParameterBinder.getBindingFor(StringQueryParameterBinder.java:75)
    at org.springframework.data.jpa.repository.query.StringQueryParameterBinder.bind(StringQueryParameterBinder.java:60)
    at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:101)
    at 

贴上代码:

    @Query("select u from AppUser u where u.mobile = :mobile and u.pass = :pass")
    AppUser withMobleAndPassQuery(@Param("mobile")String mobile,@Param("pass")String pass);

现在是这样不能写了么?
于是把“:” 改成“?1”,问题解决

    @Query("select u from AppUser u where u.mobile = ?1 and u.pass = ?2")
    AppUser withMobleAndPassQuery(@Param("mobile")String mobile,@Param("pass")String pass);
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值