public interface MyRepository extends JpaRepository<User, String> {
@Query(value = "select * from User where code like 'PER%'",
nativeQuery= true)
public List<User> findAllUsers(String param);
}
如何将“PER%”替换为 ?1
提前致谢。
慕的地8271018
浏览 151回答 2
2回答
收到一只叮咚
public interface MyRepository extends JpaRepository<User, String> { @Query(value = "select * from User where code like CONCAT(:param,'%')", nativeQuery= true) public List<User> findAllUsers(@Param("param") String param); }
您可以将查询参数与索引?1 查询创建和Spring Data JPA一起使用@Query(value = "select * from User where code like ?1%", nativeQuery= true)public List<User> findAllUsers(String param);或者通过名称传递参数。@Query(value = "select * from User where code like :param%", nativeQuery= true)public List<User> findAllUsers(@Param("param") String param);