On class level @RequestMapping or @RequestMapping("") will map to only root url "/".
Example
@Controller
@RequestMapping("")
public class MyController {
@ResponseBody
@RequestMapping
public String handler() {
return "response from handler()";
}
}
Running example
To try examples, run embedded tomcat (configured in pom.xml of example project below):
mvn tomcat7:run-war
Output
Check out this example as well when @RequestMapping without path is used on method level.
Example ProjectDependencies and Technologies Used: - spring-webmvc 5.0.4.RELEASE: Spring Web MVC.
- javax.servlet-api 3.0.1 Java Servlet API
- JDK 1.8
- Maven 3.3.9
|