如何在春季开机时通过POST方法发送参数?
我想在春季启动时通过POST方法发送参数,但参数全部为空。如何在春季开机时通过POST方法发送参数?
@RequestMapping(value = "/upload", method = RequestMethod.POST) public String upload(@RequestParam(value = "path", defaultValue = "") String path) { 
    return "hello " + path; 
} 
,当我试图测试它这个错误是出现
{     "timestamp": 1512262419197, 
    "status": 500, 
    "error": "Internal Server Error", 
    "exception": "org.springframework.web.bind.MissingPathVariableException", 
    "message": "Missing URI template variable 'path' for method parameter of type String", 
    "path": "/upload" 
} 
回答:
获得这一“路径”的唯一方法变量是构造一个URL如下
..../upload?path=foo ,如果你想要接收身体,则必须使用@RequestBody 如果要使用类似../{id}/upload的路径变量,请使用@PathVariable
回答:
我认为你需要在参数上使用数据类。其原因是POST方法不能像那样使用。通过url调用的参数仅适用于GET方法。你需要从jquery例子中调用它。或简单的方法,你可以使用像邮递员这样的工具
@RestController @RequestMapping(value ="/api") 
public class ApiDataController 
{ 
    @RequestMapping(value = "/upload", method = RequestMethod.POST) 
    public String upload(@ModelAttribute UploadForm form) 
    { 
     return "hello " + form.path; 
    } 
    public class UploadForm 
    { 
     public string path = ""; 
     public UploadForm() { 
      // TODO Auto-generated constructor stub 
     } 
     public String getPath() { 
      return path; 
     } 
     public void setPath(String path) { 
      this.path = path; 
     } 
    } 
} 
以上是 如何在春季开机时通过POST方法发送参数? 的全部内容, 来源链接: utcz.com/qa/259038.html




