Mybatis报错
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'tracking_no' in 'class entity.TrackingOrder'
### The error may involve mapper.TrackMapper.insertTrackOrder-Inline
### The error occurred while setting parameters
### SQL: insert into tracking_order(tracking_no,tracking_company,tracking_type,send_time,sender,sender_mobile,sender_address, receiver,receiver_address,tracking_fee,pay_type,pay_status,tracking_status) values(?,?,?,now(),?,?,?, ?,?,?,?,?,?)
### Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'tracking_no' in 'class entity.TrackingOrder'
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at jdk.proxy2/jdk.proxy2.$Proxy2.insertTrackOrder(Unknown Source)
at service.TrackService.insertTrackOrder(TrackService.java:50)
at service.TrackService.main(TrackService.java:35)
Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'tracking_no' in 'class entity.TrackingOrder'
at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:419)
at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:164)
at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:162)
at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:49)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)
at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:79)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:93)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:64)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
... 6 more
主要错误是There is no getter for property named ‘tracking_no’ in ‘class entity.TrackingOrder’
查找entity中TrackingOrder类发现没有错误
从TrackMapper.xml中找错误发现语句中没有对应驼峰命名
<insert id="insertTrackOrder" parameterType="entity.TrackingOrder">
insert into tracking_order(tracking_no,tracking_company,tracking_type,send_time,sender,sender_mobile,sender_address,
receiver,receiver_address,tracking_fee,pay_type,pay_status,tracking_status)
values(#{tracking_no},#{tracking_company},#{tracking_type},now(),#{sender},#{sender_mobile},#{sender_address},
#{receiver},#{receiver_address},#{tracking_fee},#{pay_type},#{pay_status},#{tracking_status})
</insert>
修改后
<insert id="insertTrackOrder" parameterType="entity.TrackingOrder">
insert into tracking_order(tracking_no,tracking_company,tracking_type,send_time,sender,sender_mobile,sender_address
receiver,receiver_address,tracking_fee,pay_type,pay_status,tracking_status)
values(#{trackingNo},#{trackingCompany},#{trackingType},now(),#{sender},#{senderNumber},#{senderAddress},
#{receiver},#{receiverAddress},#{trackingFee},#{payType},#{payStatus},#{trackingStatus})
</insert>