spring 3 mvc requestmapping dynamic param problem
I have the following code which works fine with http://localhost:8080/HelloWorldSpring3/forms/helloworld
but i want to have url have some thing like this
http://localhost:8080/HelloWorldSpring3/forms/helloworld/locname_here/locid_here
I found that adding this @RequestMapping("/helloworld/**") will w开发者_StackOverflow中文版ork but when i try to access
http://localhost:8080/HelloWorldSpring3/forms/helloworld/locname_here/locid_here
it is not found.
Web.xml entry as follows
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/forms/*</url-pattern>
</servlet-mapping>
Mapping bean entry
@RequestMapping("/helloworld/**")
public ModelAndView helloWord(){
String message = "Hello World, Spring 3.0!";
return new ModelAndView("helloworld", "message",message);
}
@Controller
@RequestMapping(value="/helloworld")
public class HelloWorldController{
@RequestMapping(value = "/{locname_here}/{locid_here}")
public ModelAndView helloWorld(@PathVariable String locname_here, @PathVariable long locid_here) {
//Logic
}
}
The above code works for your requirement.
精彩评论