|
@@ -0,0 +1,49 @@
|
|
1
|
+package com.controller;
|
|
2
|
+
|
|
3
|
+import com.pojo.Student;
|
|
4
|
+import org.springframework.stereotype.Controller;
|
|
5
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
6
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
7
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
8
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
9
|
+
|
|
10
|
+import java.util.List;
|
|
11
|
+
|
|
12
|
+@Controller
|
|
13
|
+public class ParamController {
|
|
14
|
+ // 基本类型参数
|
|
15
|
+ // http://localhost:8083/param1?name=zxy&age=11
|
|
16
|
+ @RequestMapping("/param1")
|
|
17
|
+ @ResponseBody
|
|
18
|
+ public void param1(String name,Integer age) {
|
|
19
|
+ System.out.println(name);
|
|
20
|
+ System.out.println(age);
|
|
21
|
+ }
|
|
22
|
+ // 获取pojo类型的参数
|
|
23
|
+ // http://localhost:8083/param2?name=zxy&age=11
|
|
24
|
+ @RequestMapping("param2")
|
|
25
|
+ @ResponseBody
|
|
26
|
+ public void param2(Student student) {
|
|
27
|
+ System.out.println(student.getAge());
|
|
28
|
+ }
|
|
29
|
+ // 获取数组类型的参数
|
|
30
|
+ // http://localhost:8083/param1?name=zxy&name=zxy2&name=zxy3
|
|
31
|
+ @RequestMapping("param3")
|
|
32
|
+ @ResponseBody
|
|
33
|
+ public void param3(String[] name) {
|
|
34
|
+ System.out.println(name);
|
|
35
|
+ }
|
|
36
|
+ // 获取集合类型参数
|
|
37
|
+ @RequestMapping("param4")
|
|
38
|
+ @ResponseBody
|
|
39
|
+ public void param4(@RequestBody List<Student> students) {
|
|
40
|
+ System.out.println(students);
|
|
41
|
+ }
|
|
42
|
+ // 使用RequestParam
|
|
43
|
+ // http://localhost:8083/param5?Name=%E5%BC%A0
|
|
44
|
+ @RequestMapping("param5")
|
|
45
|
+ @ResponseBody
|
|
46
|
+ public void param5(@RequestParam(name = "Name1",required = false) String name) {
|
|
47
|
+ System.out.println(name);
|
|
48
|
+ }
|
|
49
|
+}
|