【发布时间】:2016-09-28 08:44:41
【问题描述】:
我有这个简单的映射器
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0 Powerhouse//EN" "http://mybatis.org/dtd/mybatis-3-Powerhouse-mapper.dtd">
<mapper namespace="nl.powerhouse.data.domain.CountryMapper">
<resultMap id="countryDsoMap" type="nl.powerhouse.domain.common.types.algemeen.Land">
<id column="land_id"/>
<association property="landId" columnPrefix="land_" column="id"/>
<association property="landcode" columnPrefix="land_" column="landcode"/>
<association property="landnaam" columnPrefix="land_" column="landnaam"/>
<association property="landnummer" columnPrefix="land_" column="landnummer"/>
<association property="handelsland" columnPrefix="land_" column="handelsland"/>
</resultMap>
<select id="findCountryByCode" resultMap="countryDsoMap">
select <includeColumns tableAlias="land" columnPrefix="land_" refid="nl.powerhouse.data.dao.algemeen.LandMapper.Base_Column_List"/>
from alg_t_land land
where landcode = #{countryCode}
</select>
还有这个 Land.java 类
public final class Land implements Serializable {
private LandId landId;
private String landcode;
private String landnaam;
private String landnummer;
private boolean handelsland;
public Land() {
// default constructor for mybatis
}
// getters...
}
但是,当我尝试使用它时,我收到以下错误:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.NullPointerException
### The error may exist in nl/powerhouse/data/domain/CountryMapper.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
...
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
我知道查询正在运行,问题出在 resultMap 上,有什么提示吗?
【问题讨论】:
-
您的 id:
<id column="land_id"/>没有属性property。我想您需要输入<id column="land_id" property="landId"/>或属性ID 如何在Land中调用 -
我试过了,但也没有用
-
否则,你为什么使用标签
association?将替换为 。示例: <result property="handelsland" columnPrefix="land_" column="handelsland"/> -
结果有效,谢谢!