sta*_*man 3 java persistence java-ee mybatis mybatis-generator
我只是想用Mybatis映射一个布尔值,但是我遇到了问题。首先,我将向您展示涉及的部分:
XML File:
<resultMap id="destinationTypeMap" type="DestinationTypeDTO">
<result property="destinationTypeId" column="education_destination_type_id" javaType="java.lang.Long" jdbcType="NUMERIC"/>
<result property="description" column="description" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="available" column="is_available" javaType="boolean" jdbcType="VARCHAR" typeHandler="BooleanHandler"/>
</resultMap>
Run Code Online (Sandbox Code Playgroud)
Java类:
public class DestinationTypeDTO {
private long destinationTypeId;
private String description;
private boolean available;
public long getDestinationTypeId() {
return destinationTypeId;
}
public void setDestinationTypeId(long destinationTypeId) {
this.destinationTypeId = destinationTypeId;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isAvailable() {
return available;
}
public void setAvailable(boolean available) {
this.available = available;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我收到此错误日志:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Could not set property 'isAvailable' of '....DestinationTypeDTO@bbd76bf' with value 'true' Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'isAvailable' in 'class ....DestinationTypeDTO'
Run Code Online (Sandbox Code Playgroud)
我花了几个小时试图找到正在发生的事情,但是没有成功。有什么提示吗?
感谢大家。
更改javaType="boolean"到java.lang.Boolean并指定property="available"
<result property="available" column="is_available" property="available" javaType="java.lang.Boolean" jdbcType="VARCHAR" typeHandler="BooleanHandler"/>
Run Code Online (Sandbox Code Playgroud)
在你的类变private boolean available;来private Boolean isAvailable;和附加的getter / setter
public void setIsAvailable(Boolean available) {
this.available = available;
}
public Boolean getIsAvailable() {
return available;
}
Run Code Online (Sandbox Code Playgroud)