Does jpa have a dynamic query similar to mybatis?

jpa uses findby query. If the parameter is empty, it is not used as a condition. What can I do?
this function is similar to where < if test="xx! = null" > column = xx < / if > of mybatis.
for example, I have a findByNameAndAge (String name,Integer age); . When age is empty,
only queries by name, and age is not a condition.
none of the online searches use the findBy model.
Thank you

Sep.19,2021

doesn't seem to have it. Use JdbcTemplate to do it.


most complex queries cooperate with JdbcTemplate to use


if you want to ignore null, you can directly use JPA's sample query, which ignores null values.


I'll show you the code spring data jpa later. Now we mainly use jooq , combined with jdk8 function. Dynamic sql , return primary key, batch, stored procedure call, etc.
if necessary, I will set up a framework for everyone to communicate and learn


  1. one solution is Example Matchers mentioned above. You can dynamically construct ExampleMatcher. For more information, please see https://docs.spring.io/spring., and search for Example Matchers keyword chapter
  2. .
  3. can also use the criteria interface of JPA. For dynamic construction of Predicate,demo, please refer to this article: https://javadeveloperzone.com..
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3206c-4036c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3206c-4036c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?