score:229
Accepted answer
You can use the params
parameter to filter by HTTP parameters. In your case it would be something like:
@RequestMapping(value = "/searchUser", params = "userID")
public String searchUserById(@RequestParam long userID, Model model) {
// ...
}
@RequestMapping(value = "/searchUser", params = "userName")
public ModelAndView searchUserByName(@RequestParam String userName) {
// ...
}
score:0
Any way incase of request param null is allowed if you don't pass any value it will be null then you can write your coad like:
@RequestMapping(value = "/searchUser", params = {"userID","userName"})
public String searchUserById(@RequestParam long userID,@RequestParam String
userName,
Model model) {
if(userID != null){
//..
}else{
// ...
}
Source: stackoverflow.com
Related Query
- create two method for same url pattern with different arguments
- Create two methods for the same URL pattern with different arguments (with argument and without argument)
- Configure two @InitBinder to work with the same Model or Entity but for different @RequestMappings
- Spring - two different POST methods with the same URL but different produced content type
- How to create two instances of the same spring controller, each with a different base @requestMapping
- How to map two different urls in a Controller: one url with param and the same without the param?
- How i can use different url with same method in Controller With @GetMapping?
- Design pattern for Implementations with constructors autowired to different arguments
- I want to load two welcome files in web.xml for two different url pattern
- Two controllers with same name under different packages in Spring
- How can you have two URL routes mapped to the same handler method in Spring MVC (3.0)?
- Consuming different input JSON format by same URL and same method in Spring RESTful service
- @RequestMapping with "params" on same URL in different classes cause "IllegalStateException: Cannot map handler" in JUnit with SpringJUnit4ClassRunner
- Accept two different subclasses with same @RequestMapping
- Spring MVC 3: same @RequestMapping in different controllers, with centralised XML URL mapping (hybrid xml/annotations approach)
- Using Spring Security in order to display different content for the same URL based upon whether or not the user is authenticated
- Is it possible to map the same mapping with different methods to two different controllers?
- How to create form with two input line on the same line?
- In spring MVC How do I map same URL with different controller methods based on the payload?
- Spring Filter For URL Pattern with Path Variable
- Why RequestMappings with the same URL but producing different MediaTypes works?
- How can two urls with single dispatcher servlet and servlet config be mapped to different packages and a package should allow only one URL out of two?
- Spring MVC - How do I call the same URL with different mapping annotations
- How to assign the same controller method to handle two forms on two different views?
- How to use two different entities in the same persistence.xml with JPA and Spring?
- Same controller for different url
- how to create two actions on the same Controller for the same jsp page in spring-mvc
- How to assign different controller method to handle two fifferent forms on the same page
- Spring RESTful GET method with same parameters and different return type
- how to send two different types of JSON response for a same request based on the input REST?
More Query from same tag
- Spring MVC mvc:resources location attribute
- Spring MVC + Hibernate: How to handle form with relation
- How to update object with relation to list of objects via thymeleaf form
- Hibernate update Primary Key, Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
- Jetty Annotation Timeout Reason
- SpringMVC @PathVariable is truncated
- Unable to determine the correct call signature - multiple procedures/functions/signatures error while using simpleJdbcCall
- Is there a way to know which full URL the Spring controller is going to map?
- Lazy initialize in Spring MVC
- Can I inject an instance of a model class annoted with @Entity into a controller using Spring?
- Can MVC Model 2 Web App be faster in performance than Model1 web App?
- JAVA: Restfull web service not passing parameter correctly
- How to redirect to spring controller method in app deployed on local server?
- Spring security : handling SSO and DB users
- How to change MaxInactiveIntervalInSeconds value in spring session java based configuration?
- UrlFilenameViewController keeping URL extension in the view name
- spring mvc template project maven plugin error
- Thymeleaf date field is passed as null to controller
- How to configure sessionListener use spring boot 1.x
- How to add HTML-Payload for all redirections via Location-Header
- Spring OutputStream - download pptx with IE
- How to serve static pages
- Filter invoke twice when register as Spring bean
- Spring Mvc Form Post HTTP Status 400 The request sent by the client was syntactically incorrect
- Ajax spring mvc csv file upload error Required request part 'file' is not present
- Error in AplicationContext schema in Spring Application
- MVC Spring dispatcher and resource files
- Change CodeStar Spring MVC project to Spring Boot
- Unable to mock webservice client using mockito
- why does @Service not create bean