zoukankan      html  css  js  c++  java
  • jpa的@Query中"?"占位符的使用小坑

    今天使用@Query自定义查询语句,出现了一个错误:

    1 java.lang.IllegalArgumentException: Parameter with that position [1] did not exist
    2     at org.hibernate.jpa.spi.BaseQueryImpl.findParameterRegistration(BaseQueryImpl.java:502)
    3     at org.hibernate.jpa.spi.BaseQueryImpl.setParameter(BaseQueryImpl.java:692)
    4     at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:181)
    5     at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:32)

    原因是我再使用“?”占位符的时候,出现了错误,错误代码如下:

    1 @Query("SELECT id " +
    2 "FROM AbcClass " +
    3 "WHERE p2 like '%?1%'")
    4 List<Integer> findP1ByP2(String p2);

    “?”占位符应该是独立使用的,不能放在字符串中间的,上面的改正后就正常了:

    1 @Query("SELECT id " +
    2 "FROM AbcClass " +
    3 "WHERE p2 like  ?1")
    4 List<Integer> findP1ByP2(String p2);

    备注:

    个人“?”占位符使用经验
    查询条件 对应的数据类型
    =,<>,>,<,like等 Integer,String
    IN
    Collection<?>
  • 相关阅读:
    Evaluation
    Version
    bzoj4184-shallot
    jQuery 获取并设置 CSS 类
    jQuery 删除元素
    jQuery 添加元素
    jQuery 设置内容和属性
    jQuery
    jQuery Chaining
    CI 框架增加公用函数-如何使用Helper辅助函数
  • 原文地址:https://www.cnblogs.com/donfaquir/p/10073502.html
Copyright © 2011-2022 走看看