I have written the following code :
@Controller
@RequestMapping("/test")
public class Home {
@RequestMapping(value = "index")
public String index() {
return "index";
}
@RequestMapping(value = "welcome")
public String welcome(@RequestParam("txtname") String name, ModelMap model) {
model.addAttribute("msg", name);
return "index";
}
}
Now I have two doubts. I want something like /test to load index() directly. Now I have to type /test/index. How do I configure that.
Secondly index() and welcome() is almost same. Just that the request parameter is added to the output. I wrote index() because /welcome won’t work if there is no parameter. I want txtname to be made optional or something as such so that welcome can be dropped.
Just skip the extra mapping:
Try this:
Besides your
welcome()method can be simplified: