前端通过平台接口为参数绑定对象,后端收到打印出来的确实这样一个奇怪的字符串
-
代码是这样:
@Data
public class TESTDTO implements Serializable {
String params1;
String params2;
Map<String, String> params3 = new HashMap<>();public void setParams3(String params3) { System.out.println(params3); String json = params3.replace(" ", "").replace("<nil>", ""); JSONObject jsonObject = JSONObject.parseObject(json); jsonObject.forEach((k, v) -> { this.params3.put(k, (String) v); }); }
}
@GetMapping("/TEST")
public Result<?> TEST (TESTDTO testdto) {
return Result.ok("");
} -
直接用Map接收平台会打印报错这个是字符串:
Field error in object 'TESTDTO' on field 'params3': rejected value [map[aaa:111 bbb:111]]; codes [typeMismatch.TESTDTO.params3,typeMismatch.params3,typeMismatch.java.util.Map,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [TESTDTO.params3,params3]; arguments []; default message [params3]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Map' for property 'params3'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Map' for property 'params3': no matching editors or conversion strategy found]