• This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts

  • kevin
    Keymaster
    Postcount 39

    Hello anybody, Please give me sample code how to use Like queries in Spring Data JPA. Thanks


    kevin
    Keymaster
    Postcount 39

    You can see my sample code below:

    package com.demo.repositories;

    import java.util.List;
    import org.springframework.data.jpa.repository.Query;
    import org.springframework.data.repository.CrudRepository;
    import org.springframework.data.repository.query.Param;
    import org.springframework.stereotype.Repository;
    import com.demo.entities.Product;

    @Repository(“productRepository”)
    public interface ProductRepository extends CrudRepository<Product, Integer> {

    @Query(“from Product where name like :keyword%”)
    public List<Product> startsWith(@Param(“keyword”) String keyword);

    @Query(“from Product where name like %:keyword”)
    public List<Product> endsWith(@Param(“keyword”) String keyword);

    @Query(“from Product where name like %:keyword%”)
    public List<Product> contains(@Param(“keyword”) String keyword);

    }

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Top