Spring test mockmvc get request with body

问题描述

根据我的理解,当Request Method为Get时,我们不应该有Request body,我们使用@RequestParam来读取url参数。但春季测试似乎允许它。下面是一个示例代码

@Controller
public class SomeController {

    @RequestMapping(value = "/abc",method = RequestMethod.GET)
    public String greeting(@RequestBody Student student) {
        return "Hello "+ student.name;
    }

}

这是测试代码jsonStringStudent 对象的字符串表示。

@Test
    public void shouldReturnMessage() throws Exception {
        this.mockmvc.perform(get("/abc").content(jsonString)).andDo(print()).andExpect(status().isOk());
    }

我的问题是,Spring 是否应该停止允许带有 @RequestBody 请求的 Get?上面的测试运行良好,并且能够返回学生姓名。但是当我尝试使用 curl 调用相同的端点时,它会引发错误

参考:HTTP GET with request body

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)