直接上代码
//使用:name这种方式必须加,切@Param是org.springframework.data.repository.query.Param包下面的注解
@Query(nativeQuery = true, value = "select a.id,a.name,a.code,a.age,b.age as sub_age from dog a inner join dog b on a.age = b.age where a.name like concat('%',:name ,'%')")
List<Dog> findAllByAgeAfter2(@Param("name") String name);
//使用?1这种方式不需要加@Param,加了也不影响
@Query(nativeQuery = true, value = "select a.id,a.name,a.code,a.age,b.age as sub_age from dog a inner join dog b on a.age = b.age where a.name like CONCAT('%',?1,'%')")
List<Dog> findAllByAgeAfter(String name);
测试如下:
希望可以帮助到您,谢谢!