- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHelloController.java
More file actions
Latest commit
27 lines (23 loc) · 1.26 KB
/
Copy pathHelloController.java
File metadata and controls
27 lines (23 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
packagecom.controller;
importorg.springframework.stereotype.Controller;
importorg.springframework.web.bind.annotation.RequestMapping;
importorg.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping(path = "/helloController")
publicclassHelloController {
@RequestMapping(path = "/hello")
publicStringsayHello() {
System.out.println("HelloController 的 sayHello 方法执行了...");
//在SpringMVC中,return的字符串可以作为要响应的页面,/WebContent/WEB-INF/pages/success.jsp,没有写前后路径是因为在SpringMVC.xml里配置了前缀和后缀。
return"success";//返回普通的字符串,默认为响应页面的名字
}
//@RequestMapping(path = "/testRequestMapping")
//@RequestMapping(path = "/testRequestMapping", method = {RequestMethod.POST})
//@RequestMapping(path = "/testRequestMapping", method = {RequestMethod.POST},params = {"username"})
//@RequestMapping(path = "/testRequestMapping", method = {RequestMethod.POST},params = {"username=heihei"})//只有当参数也是heihei的时候才会执行,否则报错。
@RequestMapping(path = "/testRequestMapping", method = {RequestMethod.GET},params = {"username=heihei"},headers = {"Accept"})
publicStringtestRequestMapping() {
System.out.println("testRequestMapping 注解测试");
return"success";
}
}