Direct to the code
//Using :name this way must be added, cut @Param is org.springframework.data.repository.query.Param package below the note
@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);
//The use of ?1 does not require the addition of @Param, and the addition of @Param does not affect
@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);
The test is as follows:
I hope I can help you, thank you!
Read More:
- [Solved] JPA query data error: Page 1 of 0 containing UNKNOWN instances
- [Solved] IDEA JPA Custome Query Error: Can‘t resolve symbol ‘Type‘
- [Solved] java.sql.SQLException: Unknown system variable cache query size
- How to Solve SQL comments error in the mybatis query
- HQL statement query error: could not resolve property [Solved]
- Mybatis query error: Exception in thread “main” org.apache.ibatis.exceptions.PersistenceException…
- [Solved] Solr8 establishes the cluster node as active, but the query reports an error
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘testApplicat
- JAVA: How to Read JSON Format Data (Web Game Development)
- Springboot controls the startup of rabbitmq through configuration files
- Mybatis-plus: How to Execute Native SQL
- How to Solve Springboot YML configurate logging.level error
- [Solved] Mybatis insert Error: Cause: java.sql.SQLException: SQL String cannot be empty
- Java will convert Excel to list set or JSON, export excel file to local, excel import and export, easyexcel tool class
- Tomcat cross server upload error 403forbidden [How to Solve]
- [Solved] Error getting generated key or setting result to parameter object. UnsupportedOperationException
- The problem of date format conversion between springboot and front end
- How to Solve mybatis-plus Paging Plug-in PaginationInnerInterceptor error
- Spring Security Upgrade to Version 5.5.7, 5.6.4 or Above to Startup Error (Version incompatibility)
- [Solved] Hibernate Error: java.lang.StackOverflowError at java.lang.Integer.toString(Integer.java:402)