I have annotated the controller with a requestmapping. I also annotated the method with another requestmapping, however it doesn't seemed to get mapped. I am using Spring 2.5.
@RequestMapping("/animals")
@Controller
public class AnimalController {
@RequestMapping(value="/tiger")
public void doSomething(...) {..}
}
Shouldn't this give me the path /animals/tiger? I have these in the context config:
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
I only get a exception saying that it isn't mapped.
You will need the @Controller annotation above the class definition. But in addition to that you need to specify the type of Request. eg is is POST or GET. An example is shown below:
@RequestMapping(value = "tiger", method = RequestMethod.GET)
Also, note that a forward slash is not needed before the String 'tiger'. This is automatic.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.