说我这个属性无效、不合法的,没有定义的
org.springframework.beans.InvalidPropertyException: Invalid property 'FEntity[0][FInspectionStandard]' of bean class [com.shunda.light.model.InspectionPlan]
controller是有定义对象的,结果在controller就报上面的错了
public ServerResponse save(InspectionPlan inspectionPlan){
ServerResponse serverResponse = xjService.sumbit(inspectionPlan);
return serverResponse;
}
InspectionPlan 对象有个属性是private List<FEntity> FEntity;
FEntity对象属性FInspectionStandard的get/set方法也有,名字也取跟前端一样。但提交就报错了。请问这是怎么回事?
js请求是这样的
let FEntity = [];
for(let i=0,len=that.FXJXMS.length;i<len;++i){
let item = {};
item.FXJXM = that.FXJXMS[i].FXJXM;
item.FInspectionStandard = that.FXJXMS[i].FInspectionStandard;
item.F_STKD_Weight = that.FXJXMS[i].F_STKD_Weight;
item.FIsNormal = "true";
item.FInspectionState = "1";
FEntity.push(item);
}
axios.post('/xj/save',{
'FCheckplanID': that.FXJXMS[0].FCheckplanID,
'FInspectionLocationID': that.FXJXMS[0].FInspectionLocationID,
'FInspectionPlaceID': that.FXJXMS[0].FInspectionPlaceID,
'FXJTypeId': that.FXJXMS[0].FXJTypeId,
'FXJType': that.FXJXMS[0].FXJType,
'FRate': that.FXJXMS[0].FRate,
'FRateUnit': that.FXJXMS[0].FRateUnit,
'FDate': FDate,
'FEntity': FEntity,
},{
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function (res) {
console.log(res.data)
});
根据你的描述,表面看,你需要传一个数组参数。
你的定义的实体类字段建议换个命名方式,如小驼峰(idCard),或者下划线分割(id_card)
简单的创建一个测试类
@Data
static class Type {
// 没加这个之前
// @JsonProperty("FInspectionStandard")
private String FInspectionStandard ;
}
@Test
public void testCase6() throws Exception {
ObjectMapper mapper = new ObjectMapper();
Type type = mapper.readValue("{ \"FInspectionStandard\": \"DEMO\" }", Type.class);
System.out.println(type);
}
结果日志
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "FInspectionStandard" (class com.examples.springdemo.JsonTest$Type), not marked as ignorable (one known property: "finspectionStandard"])
at [Source: (String)"{ "FInspectionStandard": "DEMO" }"; line: 1, column: 28] (through reference chain: com.examples.springdemo.JsonTest$Type["FInspectionStandard"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:1127)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:2036)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1700)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1678)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:320)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:177)
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4674)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3629)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3597)
at com.examples.springdemo.JsonTest.testCase6(JsonTest.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:214)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:210)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.util.ArrayList.forEach(ArrayList.java:1255)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.util.ArrayList.forEach(ArrayList.java:1255)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
加上@JsonProperty("FInspectionStandard")
来明确接收这个字段,, 这个注解是jackson的, 按照实际使用的框架取找对应的
要么把FEntity这个字段转成字符串,后台也是用String接收,再转成List;
要么前端axios的contentType换成application/json,用json传给后台接收
org.springframework.beans.InvalidPropertyException
异常通常发生在Spring框架试图通过属性名来设置bean的属性时,但找不到相应的setter方法或属性名与setter方法不匹配。
在你给出的场景中,异常提示Invalid property 'FEntity[0][FInspectionStandard]'
,这表明Spring试图访问InspectionPlan
对象的FEntity
列表的第一个元素的FInspectionStandard
属性。但是,由于某种原因,这个操作失败了。
这里有几个可能的原因和解决方案:
数据绑定问题:
由于你的JS请求设置了Content-Type
为application/x-www-form-urlencoded
,Spring将尝试将表单数据绑定到InspectionPlan
对象。但是,对于嵌套的对象(如列表中的对象),这种绑定方式可能不会按预期工作。
解决方案:
Content-Type
为application/json
,并确保你的后端能够处理JSON数据。@RequestBody
注解来自动将JSON数据绑定到InspectionPlan
对象。FEntity
对象和FInspectionStandard
的getter和setter方法都存在,但确保它们遵循Java Bean的命名规范,即getter方法应该是getFInspectionStandard()
,setter方法应该是setFInspectionStandard(...)
。application/x-www-form-urlencoded
内容类型,并且你的数据是复杂的(如列表中的对象),你可能需要自定义属性编辑器来处理这种数据绑定。FEntity
列表已经被正确初始化,并且每个FEntity
对象都是有效的。最后,这里是一个使用@RequestBody
和application/json
的示例,它应该能够解决你的问题:
JS请求:
axios.post('/xj/save', {
// ... 其他属性
'FEntity': JSON.stringify(FEntity), // 注意这里可能需要序列化FEntity,但通常整个对象都会序列化
}, {
headers: {
'Content-Type': 'application/json'
}
}).then(function (res) {
console.log(res.data);
});
Controller:
@PostMapping("/xj/save")
public ServerResponse save(@RequestBody InspectionPlan inspectionPlan) {
ServerResponse serverResponse = xjService.sumbit(inspectionPlan);
return serverResponse;
}
注意:在上面的JS请求中,我使用了JSON.stringify(FEntity)
来序列化FEntity
对象。但是,通常当你将整个对象作为JSON发送时,整个对象(包括嵌套的对象和列表)都会被序列化,所以你可能不需要显式地序列化FEntity
。这取决于你的具体实现和需要。
失败:生成失败,出现异常。 > 其中:Script“C:\flutter\packages\flutter_tools\gradle\flutter.gradle”行:900 错误:任务“:app:CompileFlutterBuildDebug”执行失败。 进程“command”C:\flutter\bin\flutter.bat“已完成,退出值为非零%1 生成在%12s中失败异常:Gradle
问题: impl: @Service public class GraduateCollegeServiceImpl extends ServiceImpl<GraduateCollegeMapper, GraduateCollege> implements IGraduateCollegeService { controller: @Api(tags="各高校") @RestController
我有一个程序使用片段,但我有一个问题,当我包括列表视图在我的传呼机当一个项目在滑动菜单选择。 这些错误是: 在制表符适配器上 公共类TabsPagerAdapter扩展FragmentStatePagerAdapter{ } 行中的错误: public FragmentActivity getItem(int index){ 此行有多个标记-实现android.support.v4.app.Fra
在线地址, https://stackblitz.com/edit/vue-c98wtb?file=src%2Fcomponents%... 先把数据往下滚动一下,然后再点击 Recovery 按钮, 视图没有更新
2020年4月19日11:14:30 PM com.mchange.v2.resourcepool.basicresourcepool警告:由于无法获取资源,com.mchange.v2.resourcepool.basicresourcepool@7439cf4b正在中断所有等待资源签出的线程。将重试以响应新的客户端请求。2020年04月19日11:14:30 PM org.hibernate.
附注:我试着把hadoop作为一个单节点安装,但不起作用,所以我试着把它删除,把所有的东西都作为一个双节点设置来重做,所以我不得不重新格式化NameNode。我不知道这是否会影响到这一点。 编辑1:我修正了start-all.sh命令不工作,因为我修正了.bashrc中的错误。但是,当运行start-all.sh或start-dfs.sh等时,我会收到这些错误消息。 编辑2:修正了上面的错误,我更