There is no getter for property named 'user' in 'class com.jyr.wh.domain.User' 异常(示例

Posted skyxia

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了There is no getter for property named 'user' in 'class com.jyr.wh.domain.User' 异常(示例相关的知识,希望对你有一定的参考价值。

今天在使用mybatis时,出现了一个问题:There is no getter for property named ‘user‘ in ‘class com.jyr.wh.domain.User,现记录下来

使用注解的形式写sql语名,参数为一个对象

以下为正确写法:

@Insert(
"INSERT INTO t_user(openId,nickName,gender,language,city,province,country," +
"avatarUrl,unionId,appid,timestamp) " +
"VALUES(#{openId},#{nickName},#{gender},#{language},#{city},#{province},#{country}," +
"#{avatarUrl},#{unionId},#{watermark.appid},#{watermark.timestamp})"
)
int insert(User user);

 

 

 

 

 

import java.io.Serializable;

public class User implements Serializable {

private String openId;
private String nickName;
private String gender;
private String language;
private String city;
private String province;
private String country;
private String avatarUrl;//头像
private String unionId;
private WaterMark watermark;

public class WaterMark{
private String appid;
private String timestamp;
}
}
}

以上省略get、set方法

 

 

 

 

 

 

 

 

 

 

 

 

报错找不到user那是因为我的sql写错了,在values的参数中加了形参

@Insert(
"INSERT INTO t_user(openId,nickName,gender,language,city,province,country," +
"avatarUrl,unionId,appid,timestamp) " +
"VALUES(#{user.openId},#{user.nickName},#{user.gender},#{user.language},#{user.city},#{user.province},#{user.country}," +
"#{user.avatarUrl},#{user.unionId},#{user.watermark.appid},#{user.watermark.timestamp})"
)
int insert(User user);

 

 

 

 

 

在使用注解方式时形参不用写,只写传的对象的属性即可,加上会报以上错误。

 

 

~~~~~~~~~~ 完 ~~~~~~~~~~~~

 



































以上是关于There is no getter for property named 'user' in 'class com.jyr.wh.domain.User' 异常(示例的主要内容,如果未能解决你的问题,请参考以下文章

mybatis出现There is no getter for property named ...的原因及解决办法

There is no getter for property named 'NULL' in ……

Mybatis单个参数报错: There is no getter for property named

Mybatis单个参数报错: There is no getter for property named

Mybatismybatis查询报错org.apache.ibatis.reflection.ReflectionException: There is no getter for propert(代

Mybatis单个参数的if判断(针对异常:There is no getter for property..)------mybatis的内置对象