版权声明:本文为博主原创文章,无需授权即可转载,甚至无需保留以上版权声明,转载时请务必注明作者。
https://blog.csdn.net/weixin_43453386/article/details/84136214
解决——》MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'renderStatus' in 'class java.lang.Integer'
1、操作
Spring Boot + mybatis,进行查询
2、现象(错误信息)
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'renderStatus' in 'class java.lang.Integer'
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy114.selectOne(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy152.countByRenderStatus(Unknown Source)
at com.ejudata.platform.service.imp.LayoutMaterialServiceImpl.createRender(LayoutMaterialServiceImpl.java:160)
at com.ejudata.platform.test.TestRenderTask.createRender(TestRenderTask.java:25)
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.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
3、原因
在DAO方法中定义的参数 与 实体中定义的属性不一致 导致的。
原代码
1) DAO层
int countByRenderStatus(Integer renderStatus);
2) XML层
<select id="countByRenderStatus" resultType="java.lang.Integer">
select count(1) from layout_material
where 1=1
and render_status = #{renderStatus}
<if test="renderStatus==3">and (photo_url is null or photo_url ='')</if>
and order_type = 2
</select>
4、解决
第一种方案:DAO代码不变,调整XML代码
1) DAO层:不变
int countByRenderStatus(Integer renderStatus);
2) XML层:调整
把<if test="renderStatus==3">
中的 renderStatus 改为 _parameter
<select id="countByRenderStatus" resultType="java.lang.Integer">
select count(1) from layout_material
where 1=1
and render_status = #{renderStatus}
<if test="_parameter==3">and (photo_url is null or photo_url ='')</if>
and order_type = 2
</select>
第二种方案:DAO代码调整,XML代码不变
1) DAO层:调整
参数前面加上注解@Param("renderStatus")
int countByRenderStatus(@Param("renderStatus") Integer renderStatus);
2) XML层:不变
<select id="countByRenderStatus" resultType="java.lang.Integer">
select count(1) from layout_material
where 1=1
and render_status = #{renderStatus}
<if test="renderStatus==3">and (photo_url is null or photo_url ='')</if>
and order_type = 2
</select>