码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-12-31 15:49:07      阅读:323      评论:0      收藏:0      [点我收藏+]

标签:今天   use   height   找不到   头像   into   tis   getter   time   

今天在使用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' 异常

标签:今天   use   height   找不到   头像   into   tis   getter   time   

原文地址:https://www.cnblogs.com/skyxia/p/10202068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!