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);