创建Bean对象:
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
28
|
package com.awaimai.web; public class Student { private String firstName; private String lastName; public void setFirstName(String firstName) { this .firstName = firstName; } public String getFirstName() { return firstName; } public void setLastName(String lastName) { this .lastName = lastName; } public String getLastName() { return lastName; } } |
控制器:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
package com.awaimai.web; import org.springframework.web.bind.annotation.*; @RestController public class kzq { @RequestMapping (value = "/test2" ) public String test2(Student student) { String a = student.getFirstName(); String b = student.getLastName(); return a+b; } } |
web访问:
==================================================================
// http://localhost:8080/test291?firstName=zhangsi&lastName=wanGwu // zhangsiwanGwu @RequestMapping(value = "/test291") public String test281(Student student) { String a = student.getFirstName(); String b = student.getLastName(); return a+b; }
package com.bulunzhihao.web; public class Student { private String firstName; private String lastName; public void setFirstName(String firstName) { this.firstName = firstName; } public String getFirstName() { return firstName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getLastName() { return lastName; } }
http://localhost:8080/test291?firstName=zhangsi&lastName=wanGwu
---------------------------------------------------------------------------------------------------------------------------------------