spring的三种传参方式

2019-08-15  本文已影响0人  初阳拾叁

[TOC]

1.get参数

  @RequestMapping(value = "/{appId}/url", method = RequestMethod.GET)
    @ResponseBody
    public String getParam1(@PathVariable Long appId, @RequestParam String url) {
        System.out.println(appId);
        System.out.println(url);
        return "redirect:" + StringEscapeUtils.unescapeHtml(url);
    }
image-20190815103207039

2.body传输数据

  @RequestMapping(value = "/url", method = RequestMethod.POST)
    @ResponseBody
    public String getParam2(@RequestBody Param param) {
        System.out.println(param.getAppId());
        System.out.println(param.getUrl());
        return "redirect:" + StringEscapeUtils.unescapeHtml(param.getUrl());
    }



@Data
@NoArgsConstructor
@AllArgsConstructor
public class Param {
    Long   appId;
    String url;
}
image-20190815104307189

3.form传输数据

    @RequestMapping(value = "/url", method = RequestMethod.GET)
    @ResponseBody
    public String getParam3(Param param) {
        System.out.println(param.getAppId());
        System.out.println(param.getUrl());
        return "redirect:" + StringEscapeUtils.unescapeHtml(param.getUrl());
    }


@Data
@NoArgsConstructor
@AllArgsConstructor
public class Param {
    Long   appId;
    String url;
}
image-20190815104656744
上一篇下一篇

猜你喜欢

热点阅读