添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
冷冷的沙发  ·  golang mysql datetime ...·  11 月前    · 
冷静的香菇  ·  crash on ...·  1 年前    · 
  • | Sign In
  • Ask Question
  • Either use @Param on all parameters except Pageable and Sort typed once, or none at all

    Spring

    I am creating Spring Boot application using CrudRepository.


    public interface UserRepository extends CrudRepository<User, Integer> { @Query(value= "INSERT INTO User (name, gender, isMarried) VALUES (:name, :gender, :isMarried)") void saveUser(@Param("name") String name, @Param("gender") String gender, Boolean isMarried);

    Getting error for @Param. Why?

    Caused by: java.lang.IllegalArgumentException: Either use @Param on all parameters except Pageable and Sort typed once, or none at all at org.springframework.util.Assert.isTrue(Assert.java:122) ~[spring-core-6.0.11.jar:6.0.11] at org.springframework.data.repository.query.Parameters.assertEitherAllParamAnnotatedOrNone(Parameters.java:375) ~[spring-data-commons-3.1.3.jar:3.1.3] at org.springframework.data.repository.query.Parameters.<init>(Parameters.java:137) ~[spring-data-commons-3.1.3.jar:3.1.3] at org.springframework.data.repository.query.Parameters.<init>(Parameters.java:73) ~[spring-data-commons-3.1.3.jar:3.1.3] at org.springframework.data.jpa.repository.query.JpaParameters.<init>(JpaParameters.java:46) ~[spring-data-jpa-3.1.3.jar:3.1.3] at org.springframework.data.jpa.repository.query.JpaQueryMethod.createParameters(JpaQueryMethod.java:451) ~[spring-data-jpa-3.1.3.jar:3.1.3] at org.springframework.data.jpa.repository.query.JpaQueryMethod.createParameters(JpaQueryMethod.java:66) ~[spring-data-jpa-3.1.3.jar:3.1.3] at org.springframework.data.repository.query.QueryMethod.<init>(QueryMethod.java:86) ~[spring-data-commons-3.1.3.jar:3.1.3] at org.springframework.data.jpa.repository.query.JpaQueryMethod.<init>(JpaQueryMethod.java:113) ~[spring-data-jpa-3.1.3.jar:3.1.3] at org.springframework.data.jpa.repository.query.DefaultJpaQueryMethodFactory.build(DefaultJpaQueryMethodFactory.java:44) ~[spring-data-jpa-3.1.3.jar:3.1.3] at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:94) ~[spring-data-jpa-3.1.3.jar:3.1.3]

    Error message states clearly.

    "Either use @Param on all parameters except Pageable and Sort typed once, or none at all"

    It means

    1. Use @Query with @Param for all parameters.

    void saveUser(@Param("name") String name, @Param("gender") String gender, @Param("isMarried") Boolean isMarried); }

    2. Or with none.

    void saveUser(String name, String gender, Boolean isMarried);