我现在有个User对象,里面有个字段‘经销商
public class User implements Serializable{’
private static final long serialVersionUID = 1L;
private long ID;
private String userName;
private String password;
private String name;
private User dealer;//经销商
private String contact;//联系人
private String telephone;
private String lastLoginIP;//最后登录IP
private Date lastLoginTime;//最后登录时间
private int loginNum;//登录次数
private String email;
private String address;
private double balance;//账户余额
private Date createTime = new Date();
private boolean invalidate = false;//是否禁用
private String salt;//加密随机码
private boolean isDealer = false;//是否是经销商
//省略get set方法
}
现在我从jsp页面插入数据,添加‘经销商’字段时候进行判断,当不是供应商的时候,show一个供应商(key:id)下拉选(集合咯),等提交的时候就可以根据经销商id查到该经销商的User对象!
问题来了:
<insert id="insert" parameterType="user">
INSERT INTO users (username,password,name,dealer,contact,telephone,email,address,createTime,salt,isDealer)
VALUES (#{userName},SHA1(CONCAT(#{password},#{salt},'sleeping-lion')),#{name},#{dealer.userName},#{contact},#{telephone},#{email},#{address},#{createTime},#{salt},#{isDealer})
</insert>
报错如下:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'userName' in 'class java.lang.Boolean'
org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365)
com.sun.proxy.$Proxy28.insert(Unknown Source)
org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:237)
org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:79)
org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)
com.sun.proxy.$Proxy29.insert(Unknown Source)
com.tpear.CloudHealth.service.UserServiceImpl.add(UserServiceImpl.java:23)
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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
com.sun.proxy.$Proxy30.add(Unknown Source)
com.tpear.CloudHealth.action.user.UserAction.add(UserAction.java:105)
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)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:252)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.tpear.CloudHealth.action.SessionCheckInterceptor.intercept(SessionCheckInterceptor.java:62)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
重点是这句:There is no getter for property named 'userName' in 'class java.lang.Boolean';
数据库中dealer经销商字段为varchar(30)--mysql
各位大大 怎么破 头疼啊
7 个解决方案
#1
private boolean isDealer = false;//是否是经销商
把这个字段换个名字试试,应该就好了
#2
is no getter for property named 'userName' in 'class java.lang.Boolean'
private String userName;
类型报错
private String userName;
类型报错
#3
没有 我mysql里的显然是varchar啊
#4
我试试吧 但我觉得应该不是这问题 不至于说 mybatis取值都不能一一对应
#5
谢谢 我该了字段名 的确好了 但是我很费劲 这是什么原理 方便讲解下么 3q啦
#6
private User dealer;//经销商
private boolean isDealer = false;
生成getter、setter时,有两个
public boolean isDealer() {
...
}
public User getDealer() {
...
}
冲突了
#7
看不懂,这什么原理? 谁来解释下,非常感谢
#1
private boolean isDealer = false;//是否是经销商
把这个字段换个名字试试,应该就好了
#2
is no getter for property named 'userName' in 'class java.lang.Boolean'
private String userName;
类型报错
private String userName;
类型报错
#3
is no getter for property named 'userName' in 'class java.lang.Boolean'
private String userName;
类型报错
#4
private boolean isDealer = false;//是否是经销商
把这个字段换个名字试试,应该就好了
#5
我试试吧 但我觉得应该不是这问题 不至于说 mybatis取值都不能一一对应 private boolean isDealer = false;//是否是经销商
把这个字段换个名字试试,应该就好了
谢谢 我该了字段名 的确好了 但是我很费劲 这是什么原理 方便讲解下么 3q啦
#6
private User dealer;//经销商
private boolean isDealer = false;
生成getter、setter时,有两个
public boolean isDealer() {
...
}
public User getDealer() {
...
}
冲突了
#7
看不懂,这什么原理? 谁来解释下,非常感谢