0

Getting below error while calling request with multiple parameter in get request : http://localhost:8080/find/1/empid/146220

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Aug 01 19:33:35 IST 2017 There was an unexpected error (type=Internal Server Error, status=500). Name for parameter binding must not be null or empty! On JDKs < 8, you need to use @Param for named parameters, on JDK 8 or better, be sure to compile with -parameters.; nested exception is java.lang.IllegalArgumentException: Name for parameter binding must not be null or empty! On JDKs < 8, you need to use @Param for named parameters, on JDK 8 or better, be sure to compile with -parameters.

Demo.java

@Entity
public class Demo {

    @Id
    private Long id;
    private String name;
    private String value;
    //getter -setter
}

DemoApplication.java

@SpringBootApplication
@RestController
public class DemoApplication {

    @Autowired
    private DemoRepository repository;

    @RequestMapping(method=RequestMethod.GET, value="/find/{id}/{name}/{value}")
    public Demo find(@PathVariable Long id, @PathVariable String name, @PathVariable String value){
        return repository.findByIdAndNameAndValue(id, name, value);
    }
}

DemoRepository.java

public interface DemoRepository extends CrudRepository<Demo, Long>{

    @Query("select d from Demo d where d.id = :id and d.name = :name and d.value = :value")
    Demo findByIdAndNameAndValue(Long id, String name, String value);

}   

2 Answers 2

5

You need to specify the PathVariable names.

Example:

@RequestMapping(method=RequestMethod.GET, value="/find/{id}/{name}/{value}")
public Demo find(@PathVariable(name = "id") Long id, @PathVariable(name = "name") String name, @PathVariable(name = "value") String value){
    return repository.findByIdAndNameAndValue(id, name, value);
}

And in your Query method as well

Example:

@Query("select d from Demo d where d.id = :id and d.name = :name and d.value = :value")
Demo findByIdAndNameAndValue(@Param("id") Long id, @Param("name") String name, @Param("value") String value);
Sign up to request clarification or add additional context in comments.

Comments

0

Probably you should change your query to:

 @Query("select d from Demo d where d.id = ?#{[0]} and d.name = ?#{[1]} and d.value = ?#{[2]}")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.