开发获取用户列表的post请求

开发添加人员信息时需要的字段数据

首先,写一个User类,这将是添加时的字段数据

1
2
3
4
5
6
7
8
@Data
public class User {
private String userName;
private String password;
private String name;
private String age;
private String sex;
}

然后开始写怎么获取用户列表,相当于添加用户

@RequestBody User u请求post接口时,在Body填写上传的数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@RequestMapping(value = "/getUserList", method = RequestMethod.POST)
@ApiOperation(value = "获取用户列表", httpMethod = "POST")
public String getUserList(HttpServletRequest request,
@RequestBody User u){
User user;
// 获取cookies
Cookie[] cookies= request.getCookies();
// 验证cookies是否合法
for(Cookie c:cookies){
if (c.getName().equals("login")
&& c.getValue().equals("true")
&& u.getUserName().equals("zhangsan")
&& u.getPassword().equals("123456")){
user = new User();
user.setName("lisi");
user.setAge("18");
user.setSex("man");
return user.toString();
}
}
return "参数不合法";
}