Closed jiankunking closed 5 years ago
实体属性必须与数据库表字段一致,不能比数据库表字段多一些属性。 Entity attributes must be consistent with database table fields and cannot have more attributes than database table fields。
Your query returns 20 columns.
And I think you added @AutomapConstructor
to a constructor that takes more than 20 arguments.
Please let me know if I am wrong.
Assuming I am right, it may be a kind of misconfiguration, but the error message should be improved.
Your query returns 20 columns. And I think you added
@AutomapConstructor
to a constructor that takes more than 20 arguments. Please let me know if I am wrong.Assuming I am right, it may be a kind of misconfiguration, but the error message should be improved.
I did not use @AutomapConstructor,my code is as follows: entity:
@Data
@Builder
@ApiModel(description = "账号")
public class Account implements Serializable {
private static final long serialVersionUID = CocCoreVersion.SERIAL_VERSION_UID;
private Long id;
private String name;
private String nickname;
private String phoneNumber;
private Boolean phoneVerified;
private Integer sex;
private Date createdAt;
private Date updatedAt;
private Date lastLoginAt;
private String password;
private Integer passwordStrength;
private String headImgUrl;
private String address;
private Integer status;
private List<String> customerIds;
@ApiModelProperty(notes = "加密算法")
@JsonIgnore
private String encryptionAlgorithm;
private String email;
private Boolean emailVerified;
private String salt;
/**
* 职位
*/
private String position;
/**
* 员工号
*/
private String empno;
public AccountChangeMq toAccountChangeMq() {
AccountChangeMq accountChangeMq = new AccountChangeMq();
accountChangeMq.setAccountId(this.id);
accountChangeMq.setCreatedAt(this.createdAt);
return accountChangeMq;
}
public AccountDto toAccountDto() {
AccountDto accountDto = AccountDto
.builder()
.address(this.address)
.email(this.email)
.createdAt(this.createdAt)
.updatedAt(this.updatedAt)
.customerIds(this.customerIds)
.emailVerified(this.emailVerified)
.empno(this.empno)
.headImgUrl(this.headImgUrl)
//.isPrimary(this.isPrimary)
.lastLoginAt(this.lastLoginAt)
.phoneNumber(this.phoneNumber)
.phoneVerified(this.phoneVerified)
.nickname(this.nickname)
.name(this.name)
.id(this.id)
.build();
return accountDto;
}
}
mapper:
<resultMap id="AccountResultMap" type="com.jiankunking.test.account.model.po.Account">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="nickname" column="nickname"/>
<result property="phoneNumber" column="phone_number"/>
<result property="phoneVerified" column="phone_verified"/>
<result property="sex" column="sex"/>
<result property="createdAt" column="created_at"/>
<result property="updatedAt" column="updated_at"/>
<result property="lastLoginAt" column="last_login_at"/>
<result property="password" column="password"/>
<result property="passwordStrength" column="password_strength"/>
<result property="headImgUrl" column="head_img_url"/>
<result property="address" column="address"/>
<result property="status" column="status"/>
<result property="encryptionAlgorithm" column="encryption_algorithm"/>
<result property="email" column="email"/>
<result property="emailVerified" column="email_verified"/>
<result property="salt" column="salt"/>
<result property="position" column="position"/>
<result property="empno" column="empno"/>
</resultMap>
<select id="selectByPrimaryKey" parameterType="_long" resultMap="AccountResultMap">
select
id, name, nickname, phone_number, phone_verified, sex, created_at, updated_at, last_login_at, password, password_strength, head_img_url, address, status, encryption_algorithm, email, email_verified, salt, position, empno
from accounts
where id = #{accountID,jdbcType=BIGINT}
</select>
Thanks for the code, @jiankunking .
To use the result map, MyBatis needs to instantiate the Account
object first, but the only constructor has more than 20 arguments, so throwing an error is the correct behavior.
Adding a no-args constructor may fix the problem (it can be private
if you prefer).
p.s.
Please use three backticks ```
for code blocks and check the 'Preview' before submit.
Syntax highlighting is supported as well : https://guides.github.com/features/mastering-markdown#examples
Thank you for your advice @harawata Now that I know, it's me use of @Builder annotations that caused the problem. https://www.projectlombok.org/features/Builder
Thanks for the follow-up, @jiankunking ! Closing as it is not a bug.