MockMvc control层单元测试 参数传递问题
GET:
1.路径参数@PathVariable
2.表单参数@RequestParam
POST:
1.JSON请求体参数
@RequestBody
放:
1.路径参数@PathVariable
2.表单参数@RequestParam
删除:
1.路径参数@PathVariable
2.表单参数@RequestParam
MockMvc:
1.路径请求
mockMvc.perform(MockMvcRequestBuilders
.请求方式(“url / {path}”,参数值)
2.表单请求
mockMvc.perform(MockMvcRequestBuilders
.请求方式(“url”).param(“键”,“值”).contentType(MediaType.APPLICATION_FORM_URLENCODED)
3.JSON请求
MvcResult mvcResult= mvc.perform( MockMvcRequestBuilders.post("http://127.0.0.1:8080/index"). content(jsonObject.toString()). contentType(MediaType.APPLICATION_JSON) ). andExpect(MockMvcResultMatchers.status().isOk()). andDo(MockMvcResultHandlers.print()). andReturn();
)