|
@@ -1,13 +1,18 @@
|
1
|
1
|
package com.controller;
|
2
|
2
|
|
|
3
|
+import com.pojo.Student;
|
3
|
4
|
import org.aopalliance.intercept.Interceptor;
|
4
|
5
|
import org.springframework.beans.factory.annotation.Autowired;
|
5
|
6
|
import org.springframework.stereotype.Controller;
|
6
|
7
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
8
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
9
|
+import org.springframework.web.servlet.ModelAndView;
|
7
|
10
|
|
8
|
11
|
import javax.servlet.http.HttpServletRequest;
|
9
|
12
|
import javax.servlet.http.HttpServletResponse;
|
10
|
13
|
import java.io.IOException;
|
|
14
|
+import java.util.HashMap;
|
|
15
|
+import java.util.Map;
|
11
|
16
|
|
12
|
17
|
@Controller
|
13
|
18
|
public class UserController {
|
|
@@ -20,12 +25,35 @@ public class UserController {
|
20
|
25
|
// 加了前后缀 完整链接应该是 forward:/template/success.jsp
|
21
|
26
|
return "redirect:http://baidu.com";
|
22
|
27
|
}
|
|
28
|
+ // 回写数据 返回字符串
|
23
|
29
|
@RequestMapping("/save")
|
24
|
30
|
public void save(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
25
|
31
|
// 直接返回字符串
|
26
|
|
- System.out.println("1213");
|
27
|
32
|
response.getWriter().println("save");
|
28
|
|
-// return "forward:success.jsp";
|
29
|
33
|
|
30
|
34
|
}
|
|
35
|
+ // 回写数据 使用注解进行返回字符串
|
|
36
|
+ @RequestMapping("/save2")
|
|
37
|
+ @ResponseBody // 不进行视图跳转,直接进行数据响应
|
|
38
|
+ public String save2() {
|
|
39
|
+ return "save2";
|
|
40
|
+ }
|
|
41
|
+ // 回写数据 返回对象
|
|
42
|
+ @RequestMapping("/save3")
|
|
43
|
+ @ResponseBody // 不进行视图跳转,直接进行数据响应
|
|
44
|
+ public Student save3() {
|
|
45
|
+ Student student = new Student();
|
|
46
|
+ student.setName("woshinishiws");
|
|
47
|
+ return student;
|
|
48
|
+ }
|
|
49
|
+ // 回写数据 返回对象
|
|
50
|
+ @RequestMapping("/save4")
|
|
51
|
+ @ResponseBody // 不进行视图跳转,直接进行数据响应
|
|
52
|
+ public Map save4() {
|
|
53
|
+ HashMap<String, String> stringStringHashMap = new HashMap<String, String>();
|
|
54
|
+ stringStringHashMap.put("1","2");
|
|
55
|
+ return stringStringHashMap;
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+
|
31
|
59
|
}
|