两种方式:

方式一:使用json字符串解析,把json字符串解析成json对象后,通过get方法得到数据

  1. //用string接收,然后接收到的是json对象字符串,需要转化为json对象,然后通过get拿到数据
  2. @PostMapping("/getEmpByW")
  3. public RespBean getEmpByW(@RequestBody String wedlock) throws JsonProcessingException {
  4. System.out.println(wedlock);
  5. JSONObject jsonObject = JSONObject.parseObject(wedlock);
  6. System.out.println(jsonObject);
  7. String s = (String) jsonObject.get("wedlock");
  8. System.out.println(s
  9. );
  10. int employee = employeeService.getEmployee(s);
  11. System.out.println(employee);
  12. if (employee == 0) {
  13. return RespBean.error("数据错误!");
  14. }
  15. return RespBean.ok("成功", employee);
  16. }

方式二:使用hashmap的对象来接收,然后用get方法获取字符串的key

  1. //使用hashmap 当作对象接收
  2. @PostMapping("/getempbyw2")
  3. public RespBean getempbyw2(@RequestBody HashMap wedlock) {
  4. String s = (String) wedlock.get("wedlock");
  5. System.out.println(s);
  6. return RespBean.ok("ok", s);
  7. }