Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用ObjectMapper处理多个参数?_Java_Spring_Unit Testing - Fatal编程技术网

Java 如何使用ObjectMapper处理多个参数?

Java 如何使用ObjectMapper处理多个参数?,java,spring,unit-testing,Java,Spring,Unit Testing,我想知道如何测试需要多个参数的控制器(post) @RequestMapping(value = PATH_TO_OBFUSCATED, method = RequestMethod.POST) public ResponseEntity<String> download(@RequestBody String requestBody, @RequestParam("obfuscated") boolean obfiscated) { return obf

我想知道如何测试需要多个参数的控制器(post)

@RequestMapping(value = PATH_TO_OBFUSCATED, method = RequestMethod.POST)
public ResponseEntity<String> download(@RequestBody String requestBody, @RequestParam("obfuscated") boolean obfiscated) {
    return obfuscated.download(requestBody, obfiscated);
}

但是,当有>=2时,我应该如何使用ObjectMapper?

正如在评论中所说,您只有1个主体。所以可能是这样的:

 this.mockMvc.perform(
        post("/obfuscated").
            contentType(MediaType.APPLICATION_JSON).
            content(json).// <-- the body
            param("obfuscated", "true"))// <-- the param
        .andExpect(status().isOk());
this.mockMvc.perform(
post(“/obfuscated”)。
contentType(MediaType.APPLICATION_JSON)。

content(json)。//不应该。因为1是主体,请求只有一个主体,另一个是常规的reguest参数。可以使用
param(name,value)
添加该参数。
 this.mockMvc.perform(
        post("/obfuscated").
            contentType(MediaType.APPLICATION_JSON).
            content(json).// <-- the body
            param("obfuscated", "true"))// <-- the param
        .andExpect(status().isOk());