Spring MVC controller Test - print the result JSON String

前端 未结 5 2181
一向
一向 2021-01-30 05:03

Hi I have a Spring mvc controller

@RequestMapping(value = \"/jobsdetails/{userId}\", method = RequestMethod.GET)
@ResponseBody
public List jobsDetai         


        
5条回答
  •  野性不改
    2021-01-30 05:40

    The trick is to use andReturn()

    MvcResult result = springMvc.perform(MockMvcRequestBuilders
             .get("/jobsdetails/2").accept(MediaType.APPLICATION_JSON)).andReturn();
    
    String content = result.getResponse().getContentAsString();
    

提交回复
热议问题