在春天请求使用不同的参数列表映射

时间:2014-08-01 10:08:25

标签: java spring spring-mvc overloading

方法1:它接受实体和图像作为请求参数

@RequestMapping(value="/add", method={RequestMethod.POST}, params={"entity", "image"})
public String add( @RequestParam("entity") CustomEntity entity,
                @RequestParam("image") MultipartFile image) {
LOGGER.trace("Information with Image");
return "success";
}

方法2:它只接受实体和图像的请求参数

@RequestMapping(value="/add", method={RequestMethod.POST}, params={"entity")
public String add( @RequestParam("entity") CustomEntity entity) {
LOGGER.trace("Information without Image");
return "success";
}

当使用Spring Rest API进行iam测试时,它会引发400个错误请求

MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
map.add("entity", new CustomEntity());
String response = restTemplate.postForObject(SERVER_URI+"/add", map, String.class);

我需要改变什么? [链接](In a Spring controller, can I have a method called based on the number of request parameters?

0 个答案:

没有答案