Spring boot 角度5:将带有字符串参数和FormData参数的POST请求一起发送到Spring REST控制器
我想从我的服务向SpringBoot@RestController发送POST请求。我有一堆要发送的字符串参数,但我还有一个FormData参数,它是一个图像(图片参数)。如果我这样做:Spring boot 角度5:将带有字符串参数和FormData参数的POST请求一起发送到Spring REST控制器,spring-boot,angular5,spring-restcontroller,Spring Boot,Angular5,Spring Restcontroller,我想从我的服务向SpringBoot@RestController发送POST请求。我有一堆要发送的字符串参数,但我还有一个FormData参数,它是一个图像(图片参数)。如果我这样做: public createEvent(name, description, fromDate, toDate, userId, picture){ this.http.post(this.baseUrl + 'create', { name: na
public createEvent(name, description, fromDate, toDate, userId, picture){
this.http.post(this.baseUrl + 'create',
{
name: name,
description: description,
fromYear: fromDate['year'],
fromMonth: fromDate['month'],
fromDay: fromDate['day'],
toYear: toDate['year'],
toMonth: toDate['month'],
toDay: toDate['day'],
userId: userId,
picture: picture
}).subscribe();
}
@PostMapping(value = "/create")
public void createEvent(@RequestBody Map map){}
我的控制器方法如下所示:
public createEvent(name, description, fromDate, toDate, userId, picture){
this.http.post(this.baseUrl + 'create',
{
name: name,
description: description,
fromYear: fromDate['year'],
fromMonth: fromDate['month'],
fromDay: fromDate['day'],
toYear: toDate['year'],
toMonth: toDate['month'],
toDay: toDate['day'],
userId: userId,
picture: picture
}).subscribe();
}
@PostMapping(value = "/create")
public void createEvent(@RequestBody Map map){}
地图如下所示:我无法获取文件。
我可以在post请求中以单个参数的形式发送FormData,并在控制器中以多部分文件的形式接收它,而不会出现任何问题,但是否可以在同一请求中与其他参数一起发送它?显然,您可以在FormData对象中附加所有参数,并通过控制器中的@RequestParam访问它们