MyBatis不使用布尔映射 [英] MyBatis not working with Boolean mapping

查看:334
本文介绍了MyBatis不使用布尔映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想用Mybatis映射一个布尔值,但我遇到了问题。首先,我将向您展示所涉及的部分:

I am just trying to map a boolean value with Mybatis, but I am having a problem. Firstly, I'll show you the parts involved:

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>

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

}

但是,我收到此错误log:

But, I am getting this error log:

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'

我花了好几个小时试图找到正在发生的事情,但没有成功。任何提示?

I spent hours trying to find what's going on but without success. Any hint?

谢谢大家。

推荐答案

更改 javaType =boolean to java.lang.Boolean 并指定 property =available

<result property="available" column="is_available" property="available" javaType="java.lang.Boolean" jdbcType="VARCHAR" typeHandler="BooleanHandler"/>

在你的班级中更改私人布尔可用; private Boolean isAvailable; 并添加getter / setter

In your class change private boolean available; to private Boolean isAvailable; and add getter/setter

public void setIsAvailable(Boolean available) {
    this.available = available;
}

public Boolean getIsAvailable() {
    return available;
}

这篇关于MyBatis不使用布尔映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆