1

我有以下代码可以很好地与 http://localhost:8080/HelloWorldSpring3/forms/helloworld

但我想让 url 有这样的东西

http://localhost:8080/HelloWorldSpring3/forms/helloworld/locname_here/locid_here

我发现添加这个 @RequestMapping("/helloworld/**") 会起作用,但是当我尝试访问时

http://localhost:8080/HelloWorldSpring3/forms/helloworld/locname_here/locid_here

没有找到。

web.xml 入口如下

<servlet-mapping>
      <servlet-name>dispatcher</servlet-name>
      <url-pattern>/forms/*</url-pattern>
    </servlet-mapping>

映射 bean 条目

@RequestMapping("/helloworld/**")
       public ModelAndView helloWord(){
              String message = "Hello World, Spring 3.0!";
              return new ModelAndView("helloworld", "message",message);
       }
4

1 回答 1

0
@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
    }

}

上面的代码适用于您的要求。

于 2011-02-21T07:23:12.800 回答