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);

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

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

上一篇:iOS App的启动过程


下一篇:ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN