关于Converter只能转换表单提交的数据,如果是以Json的方式提交就不能转化了请问整个源码怎么分析啊
这是我的Controller
@PostMapping("/hello")
public String hello( TestDtoWrapper dto) {
return new Gson().toJson("666");
}
这是我的POJO
public static class TestDto {
private String[] mids;
public String[] getMids() {
return mids;
}
public void setMids(String[] mids) {
this.mids = mids;
}
}
public static class TestDtoWrapper {
private TestDto testDto;
public TestDto getTestDto() {
return testDto;
}
public void setTestDto(TestDto testDto) {
this.testDto = testDto;
}
}
这是我的Converter
@Component
public class SpringToTestDtoCoverter implements Converter<String, HelloWorld.TestDto> {
@Override
public HelloWorld.TestDto convert(String source) {
String[] split = source.split(",");
HelloWorld.TestDto testDto=new HelloWorld.TestDto();
testDto.setMids(split);
return testDto;
}
}
经测试,使用@RequestBody的方式接收参数,系统抛出无法转化的异常,使用表单提交数据则正常显示
希望大佬们可以告知~ 感谢!
参数上传成功转化
参数转化失败
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…