There is no getter for property named '*' in 'class java.lang.String',此错误之所以出现,是因为mybatis在对parameterType="String"的sql语句做了限制,假如你使用<when test="username != null">这样的条件判断时,就会出现该错误

报信息如下

.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'provName' in 'class java.lang.String'   at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)   at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)   at com.sun.proxy.$Proxy97.selectList(Unknown Source)   at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)   at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)   at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)   at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)   at com.sun.proxy.$Proxy125.getSchoolInfoByProvName(Unknown Source)   at cn.ls.tcis.service.impl.barnswallow.BarnSwallowInfoServiceImpl.getDistributeAge(BarnSwallowInfoServiceImpl.java:243)   at cn.ls.tcis.controller.pc.StatisticController.getDistributeAge(StatisticController.java:94)   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.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)   at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)   at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)   at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)   at org.springframework.web.servl

T.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.Reflectio_spring

 

mapper接口

T.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.Reflectio_java_02

T.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.Reflectio_spring_03

parameterType="String",这一点是必须得,参数类型必须是string。
该sql对应的mapper class中对应的方法为


List<SchoolInfoDO> getSchoolInfoByProvName(String provName);也就是说,传递的参数名为provName,正常情况下,这样的配置合情合理。<when test="provName != null">,你有一个对应的test判断语句,也可能是if。 那么这个时候,项目运行该查询语句时,就会抛出There is no getter for property named 'username' in 'class java.lang.String'错误! 


解决办法很简单,你只需要把 ​​<when test="​​​provName​​ != null">​​​修改为 ​​<when test="_parameter!= null">​​就好了

修改完以后

T.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.Reflectio_spring_04

解决方法

<if test="_parameter !=null">

</if>