mybatis配置遇到的问题There is no getter for property named 'post_title' in 'class

来源:互联网 发布:linux samba配置用户 编辑:程序博客网 时间:2024/05/22 12:20
Exception in thread "main" org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'post_title' in 'class com.idolfans.entity.Post'    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:368)    at com.sun.proxy.$Proxy8.insert(Unknown Source)    at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:240)    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:51)    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)    at com.sun.proxy.$Proxy23.addPost(Unknown Source)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)    at java.lang.reflect.Method.invoke(Unknown Source)    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)    at com.sun.proxy.$Proxy24.addPost(Unknown Source)    at com.idolfans.test.Test.main(Test.java:37)

原因是因为sql语句写错了字段

insert into post(post_title,post_content,post_date,user_id,parent_id,idol_id) value(#{post_title},#{post_content},#{post_date}, #{user_id},#{parent_id},#{idol_id});

value()括号里面写的应该是类属性,而非数据库字段

insert into post(post_title,post_content,post_date,user_id,parent_id,idol_id) value(#{postTitle},#{postContent},#{postDate}, #{user.userId},#{parentId},#{idolId});

user是映射关系,用“应用变量.属性 ”的方式与表字段匹配

阅读全文
0 0