Quantcast
Viewing all articles
Browse latest Browse all 8

How to make @RequestParam Optional

A @RequestParam can be set as optional by simply providing a default value to it as shown in the following example

@Controller
public class MyController {

  @RequestMapping(value = "/myApp", method = { RequestMethod.POST, RequestMethod.GET })
  public String doSomething(@RequestParam(value = "name", defaultValue = "anonymous") final String name) {
  // Do something with the variable: name
    return "viewName";
  }
}

Viewing all articles
Browse latest Browse all 8

Trending Articles