DEV Community

Cover image for Using Advanced LIKE Expressions in Spring boot
Tristan Elliott
Tristan Elliott

Posted on

Using Advanced LIKE Expressions in Spring boot


  • This series is about all things related to using Spring Boot for web development.

The problem

  • I was facing this problem: I have a BlogPost entity and I want to be able to query the BlogPost table in my database for any blog post containing a certain title.

The solution

@Query(value = "SELECT * FROM blogPost WHERE blogPost.title LIKE  %:title%",nativeQuery = true)
    List<BlogPost> findBlogPostByTitle(@Param("title") String title);
Enter fullscreen mode Exit fullscreen mode

The weird bug I encountered

  • I was using the the 'LIKE' operator but I kept running into a weird bug where it would only return the first value matched and not all the values. It turns out that it was due to improper syntax when passing the parameter to the SQL query. So if you are having a similar problem, check the syntax of your SQL.


  • Thank you for taking the time out of your day to read this blog post of mine. If you have any questions or concerns please comment below or reach out to me on Twitter.

Top comments (0)