两种方式:
方式一:使用json字符串解析,把json字符串解析成json对象后,通过get方法得到数据
//用string接收,然后接收到的是json对象字符串,需要转化为json对象,然后通过get拿到数据
@PostMapping("/getEmpByW")
public RespBean getEmpByW(@RequestBody String wedlock) throws JsonProcessingException {
System.out.println(wedlock);
JSONObject jsonObject = JSONObject.parseObject(wedlock);
System.out.println(jsonObject);
String s = (String) jsonObject.get("wedlock");
System.out.println(s
);
int employee = employeeService.getEmployee(s);
System.out.println(employee);
if (employee == 0) {
return RespBean.error("数据错误!");
}
return RespBean.ok("成功", employee);
}
方式二:使用hashmap的对象来接收,然后用get方法获取字符串的key
//使用hashmap 当作对象接收
@PostMapping("/getempbyw2")
public RespBean getempbyw2(@RequestBody HashMap wedlock) {
String s = (String) wedlock.get("wedlock");
System.out.println(s);
return RespBean.ok("ok", s);
}