Json方式用到了 请求体反射类SimpleVo,或者理解为类的实例化的反射,为了动态获取类的熟悉。 也就是把请求体作为对象看待,获取了对象里的属性。
@ResponseBody
@RequestMapping(value = "/jsonpost",method = RequestMethod.POST)
public Result jsonPost(@RequestBody SimpleVo vo)
{
Integer id = vo.getId();
String name = vo.getName();
Map<String, String> info = new HashMap<String, String>();
info.put("id", Integer.toString(id));
info.put("name", name);
return Result.successResult(info);
}
@RequestMapping(value = "/getinfo1", method = RequestMethod.POST)
@ResponseBody
public Result getInfo1(@RequestParam(value = "id", required = false) Integer id,
@RequestParam(value = "name") String name){
Map<String, Object> info = new HashMap<>();
info.put("id", id);
info.put("name", name);
return Result.successResult(info);
}
@Data
public static class SimpleVo {
private Integer id;
private String name;
private List<Integer> nums;
}
|