mybatis There is no setter for property named xxx

J2EE 码拜 6年前 (2015-04-03) 2070次浏览 0个评论

异常详细信息如下,报错的位置是User类的uId属性的setter方法,可是我很确定setter方法没问题。更加诡异的是如果我把uId的getter和setter方法全删掉,再写一遍,然后重新部署,竟然没问题了。然后等我再用一会,重启了几次后,这个异常 又会蹦出来。大神们有什么想法,快被这个问题整吐了。
另我一个同时说是Driver和User对应的两张表的主键名称相同(都是u_id)造成的,driver表外键引用user表

org.apache.ibatis.reflection.ReflectionException: There is no setter for property named ""uId"" in ""class com.yuedao.car.entity.User""
	at org.apache.ibatis.reflection.Reflector.getSetInvoker(Reflector.java:372)
	at org.apache.ibatis.reflection.MetaClass.getSetInvoker(MetaClass.java:174)
	at org.apache.ibatis.reflection.wrapper.BeanWrapper.setBeanProperty(BeanWrapper.java:167)
	at org.apache.ibatis.reflection.wrapper.BeanWrapper.set(BeanWrapper.java:57)
	at org.apache.ibatis.reflection.MetaObject.setValue(MetaObject.java:133)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyPropertyMappings(DefaultResultSetHandler.java:368)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:745)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(DefaultResultSetHandler.java:713)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:264)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:236)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:150)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:60)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:73)
	at org.apache.ibatis.executor.ReuseExecutor.doQuery(ReuseExecutor.java:57)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:120)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
	at $Proxy12.selectList(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
	at $Proxy58.selectUsersOfPage(Unknown Source)
	at com.yuedao.car.service.impl.UserServiceImpl.getUserList(UserServiceImpl.java:24)
	at com.yuedao.car.controller.UserController.list(UserController.java:42)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:619)
mybatis There is no setter for property named xxx
User类:

package com.yuedao.car.entity;

public class User implements java.io.Serializable{
	private static final long serialVersionUID = 1L;

	private int uId;
	private String pwd;
	private String mobileNo;
	private String userName;
	private int sex;
	private String registTime;
	private String email;
	private String photoPath;//照片路径
	private int userType;
	private int status;
	private String shareNo;//分享码
	private String token;//用户令牌
	private Account account;

	public void setuId(int uId) {
		this.uId = uId;
	}
	public int getuId() {
		return uId;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	public String getPwd() {
		return pwd;
	}
	public String getMobileNo() {
		return mobileNo;
	}
	public void setMobileNo(String mobileNo) {
		this.mobileNo = mobileNo;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public int getSex() {
		return sex;
	}
	public void setSex(int sex) {
		this.sex = sex;
	}
	public String getRegistTime() {
		return registTime;
	}
	public void setRegistTime(String registTime) {
		this.registTime = registTime;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getPhotoPath() {
		return photoPath;
	}
	public void setPhotoPath(String photoPath) {
		this.photoPath = photoPath;
	}
	public int getUserType() {
		return userType;
	}
	public void setUserType(int userType) {
		this.userType = userType;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public String getShareNo() {
		return shareNo;
	}
	public void setShareNo(String shareNo) {
		this.shareNo = shareNo;
	}
	public String getToken() {
		return token;
	}
	public void setToken(String token) {
		this.token = token;
	}
	public void setAccount(Account account) {
		this.account = account;
	}
	public Account getAccount() {
		return account;
	}
}
mybatis There is no setter for property named xxx
mybatis映射文件
mybatis There is no setter for property named xxx
mybatis There is no setter for property named xxx
mybatis There is no setter for property named xxx
10分
public void setUId(int uId) {
        this.uId = uId;
    }
    public int getUId() {
        return uId;
    }

setUId和getUId的U都要大写。

mybatis There is no setter for property named xxx
10分
不然反射的时候不认识。
mybatis There is no setter for property named xxx
10分
我用mybatis从来不用resultMap的 都用的原生态的sql,
sql里面as resulttype里面的属性就可以了  用resultMap太容易出错。
mybatis There is no setter for property named xxx
引用 3 楼 stonefeng 的回复:
public void setUId(int uId) {
        this.uId = uId;
    }
    public int getUId() {
        return uId;
    }

setUId和getUId的U都要大写。

试了下,还是不行啊,它为什么是随机出现的?
之前是用userId,setter方法是setUserId,也报这个错,改成uId也不行。
不过你说的有道理,首字母确实该大写

mybatis There is no setter for property named xxx
10分
????public?void?setuId(int?uId)?{
????????this.uId?=?uId;
????}
????public?int?getuId()?{
????????return?uId;

你 set/get 方法不是工具生成的吗。
把get/set  全删除掉,重新生成一遍。

mybatis There is no setter for property named xxx
引用 7 楼 rui888 的回复:

????public?void?setuId(int?uId)?{
????????this.uId?=?uId;
????}
????public?int?getuId()?{
????????return?uId;

你 set/get 方法不是工具生成的吗。
把get/set  全删除掉,重新生成一遍。

也不行啊,我把uId改成id,这样大小写不会有问题了吧,结果出现下面的异常

org.apache.ibatis.reflection.ReflectionException: Could not set property ""id"" of ""class com.yuedao.car.entity.User"" with value ""1"" Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named ""id"" in ""class com.yuedao.car.entity.User""
	org.apache.ibatis.reflection.wrapper.BeanWrapper.setBeanProperty(BeanWrapper.java:175)
	org.apache.ibatis.reflection.wrapper.BeanWrapper.set(BeanWrapper.java:57)
	org.apache.ibatis.reflection.MetaObject.setValue(MetaObject.java:133)
	org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyPropertyMappings(DefaultResultSetHandler.java:368)
	org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:745)
	org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(DefaultResultSetHandler.java:713)
	org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:264)
	org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:236)
	org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:150)
	org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:60)
	org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:73)
	org.apache.ibatis.executor.ReuseExecutor.doQuery(ReuseExecutor.java:57)
	org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
	org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
	org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:120)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	java.lang.reflect.Method.invoke(Method.java:601)
	org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
	$Proxy12.selectList(Unknown Source)
	org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)
	org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
	org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
	org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
	$Proxy58.selectUsersOfPage(Unknown Source)
	com.yuedao.car.service.impl.UserServiceImpl.getUserList(UserServiceImpl.java:24)
	com.yuedao.car.controller.UserController.list(UserController.java:42)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	java.lang.reflect.Method.invoke(Method.java:601)
	org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
mybatis There is no setter for property named xxx
没有id   的 set/get 方法。
mybatis There is no setter for property named xxx
你的set方法看着不对啊  应该是:setUId();getUId();   方法中u应该是大写的吧
mybatis There is no setter for property named xxx
引用 10 楼 u012353086 的回复:

你的set方法看着不对啊  应该是:setUId();getUId();   方法中u应该是大写的吧

package com.yuedao.car.entity;

public class User{
	private int id;
	private String pwd;
	private String mobileNo;
	private String userName;
	private int sex;
	private String registTime;
	private String email;
	private String photoPath;//照片路径
	private int userType;
	private int status;
	private String shareNo;//分享码
	private String token;//用户令牌
	private Account account;

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	public String getMobileNo() {
		return mobileNo;
	}
	public void setMobileNo(String mobileNo) {
		this.mobileNo = mobileNo;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public int getSex() {
		return sex;
	}
	public void setSex(int sex) {
		this.sex = sex;
	}
	public String getRegistTime() {
		return registTime;
	}
	public void setRegistTime(String registTime) {
		this.registTime = registTime;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getPhotoPath() {
		return photoPath;
	}
	public void setPhotoPath(String photoPath) {
		this.photoPath = photoPath;
	}
	public int getUserType() {
		return userType;
	}
	public void setUserType(int userType) {
		this.userType = userType;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public String getShareNo() {
		return shareNo;
	}
	public void setShareNo(String shareNo) {
		this.shareNo = shareNo;
	}
	public String getToken() {
		return token;
	}
	public void setToken(String token) {
		this.token = token;
	}
	public Account getAccount() {
		return account;
	}
	public void setAccount(Account account) {
		this.account = account;
	}
}

现在改成这种了,大小写没问题了,但是还是出这个错误。最有可能的就是user和driver表做了关联,但user和driver表的主键字段都是u_id,而我的select语句写的是select *,这样查出的结果中有两个u_id,不知道赋值给哪个了
mybatis There is no setter for property named xxx

mybatis There is no setter for property named xxx
这个算是很简单的了,就是说实体类中,有一个字段,没有get/set方法。
mybatis There is no setter for property named xxx
引用 12 楼 xmt1139057136 的回复:

这个算是很简单的了,就是说实体类中,有一个字段,没有get/set方法。

要真这么简单就好了,你看看上面我回答别人的

mybatis There is no setter for property named xxx
resultMap用的很少,你看看type=”User”找得到不,还有和数据库的字段的映射关系正确不
mybatis There is no setter for property named xxx
type、resultMap  好好审查一下,应该是这两个中的一个有错误

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明mybatis There is no setter for property named xxx
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!