What is the use of @Param.
As i saw a question regarding this.
and i am not able to find the relative answer..
http://localhost:8080/MyWebApp/main.obj?name=priya
We can use @RequestParam to retrieve the value.
My question is that can @Param be used?
In Spring Framework, @Param (org.springframework.data.repository.query.Param) is used to bind the method parameter to Query parameter.
Example:
@Query("select e from Employee e where e.deptId = :deptId")
List<Employee> findEmployeeByDeptId(@Param("deptId") Long departmentId);
Here, Employee is JPA Entity, and @Param is used to bind the method parameter departmentId to Query parameter deptId.
In your case, you are trying to fetch URL Parameter value. @RequestParam need to be used. @RequestParam is used to bind method parameter to web URL request parameter.
In Spring Data Rest @Param is used to extract values from request parameters in a RESTful endpoint method.
@RepositoryRestResource
interface ProductRepository extends JpaRepository<Product, Long> {
@RestResource(path="/findByName")
Page<Product> findByNameContains(@Param("productName") String
name,
Pageable pageable);
}
you can now access the endpoint /findByName?productName=name to search for YourEntity resources
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With