如何使用restclient来发送post请求参数

2025-03-17 09:07:13
推荐回答(1个)
回答1:

  Java代码
  @RequestMapping(value = "/test", method = { RequestMethod.GET,
  RequestMethod.POST })
  public void test(HttpServletResponse response, @RequestBody String message) {
  这里的:@RequestBody String message
  LOGGER.debug(String.format("receive message %s", message));
  Map map = Maps.newHashMap();
  
  try {
  map.put("result", message);
  Tools.printToJson(JSON.toJSONString(map), response);
  } catch (Exception e) {
  LOGGER.error(e.getMessage(), e);
  }
  }
  
  如果传递的是一个对象给springmvc,如(代码不全):
  Java代码
  public class EntitySubscribe {
  private Long entityId;
  private String entityCode;
  private String entityName;
  private String teamCode;
  private SubscribeUsesEnum subscribeUsesEnum;
  private Date gmtCreate;
  private Date gmtModify;
  private Long flowId;
  private OnOffEnum state;
  
  private String reason;
  private List uses;
  }