There is no getter for property named 'userIds' in 'class java.lang.String'

明天還有我發表於2016-03-10
2014-02-16 14:52:58.475:WARN:oejs.ServletHandler:/mideaAdmin/deleteUser.midea
org.mybatis.spring.MyBatisSystemException: nested exception isorg.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'userIds' in 'class java.lang.String'
 at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
 at $Proxy23.update(Unknown Source)
 at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:246)
 at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)
 at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:25)
 at $Proxy30.deleteUser(Unknown Source)
 at com.hailong.midea.busi.user.manager.UserManager.deleteUser(UserManager.java:80)
 at com.hailong.midea.web.controller.user.UserController.deleteUser(UserController.java:147)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
 at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:594)
 at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1365)
 at com.hailong.midea.web.filter.SessionFilter.doFilterInternal(SessionFilter.java:80)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
 at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1336)
 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
 at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
 at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
 at org.eclipse.jetty.server.Server.handle(Server.java:351)
 at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:451)
 at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:931)
 at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:857)
 at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230)
 at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:76)
 at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:609)
 at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:45)
 at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599)
 at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534)
 at java.lang.Thread.run(Thread.java:662)
Caused by: 
org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'userIds' in 'class java.lang.String'
 at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:308)
 at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:93)
 at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:134)
 at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:27)
 at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:103)
 at org.apache.ibatis.builder.xml.dynamic.DynamicContext$ContextMap.get(DynamicContext.java:72)
 at org.apache.ibatis.builder.xml.dynamic.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:90)
 at org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1657)
 at org.apache.ibatis.ognl.ASTProperty.getValueBody(ASTProperty.java:92)
 at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
 at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)
 at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:333)
 at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:413)

 at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:454)


解決方案一:
 引起問題的原因是因為在DAO方法中定義的引數 與 實體中定義的屬性不一致 導致的,
 比如DAO方法定義的是:
 
 public int deleteUser(String userIds);
 
 SQL語句如下:
 <!-- 刪除使用者(邏輯刪除) -->
 <update id="deleteUser" parameterType="String">
  UPDATE t_user t SET t.user_status = '禁用' WHERE t.user_pk_id IN(#{userIds})
 </update>
 
 UserEntity的定義:
 public class UserEntity extends AbstractEntity{
  private int userPkId;
  private String userId;
  private String userName;
  private String sex;
  private byte age;
 }
 
 這個userIds並不在UserEntity中存在,而userId是存在的,如果使用UserEntity中不存在userIds的屬性 所以會報此錯誤。改成userId 問題即可解決。


解決方案二:

出現原因
 這裡出現的問題是在DAO方法中定義的引數 與 實體中定義的屬性不一致 導致的。

解決方案:

dao層加@Param("userIds")註解即可

public List<DictItem> selectKeyByUserId(@Param("userIds") long userIds);


相關文章