문제

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 work 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top