我有一个包含三列的INSTR_ROUTING数据库表:
我的Java代码是:
public Map<String, String> getInstrumentRouting() {
return getSqlSession().selectMap(NAMESPACE_PFX + "getInstrumentRouting", "INSTR_INSTANCE_NM");
和mybatis我尝试了多种方式,最新的两种方式是:
<select id="getInstrumentRouting" resultType="java.util.HashMap">
select INSTR_ROUTING_ID as irId,
INSTR_INSTANCE_NM as instrumentName,
LAB_SYSTEM_NM as destinationName
from INSTR_ROUTING
WHERE INSTR_ROUTING_ID = #{irId, jdbcType=VARCHAR}
</select>
和
<resultMap id="instrumentRoutingMap" type="com.labcorp.adapter.di.common.InstrumentRoute">
<result column="INSTR_INSTANCE_NM" property="instrumentName"
jdbcType="VARCHAR" />
<result column="LAB_SYSTEM_NM" property="queueInstanceName"
jdbcType="VARCHAR" />
</resultMap>
<select id="getInstrumentRouting" resultMap="instrumentRoutingMap">
select INSTR_ROUTING_ID as irId,
INSTR_INSTANCE_NM as instrumentName,
LAB_SYSTEM_NM as destinationName
from INSTR_ROUTING
WHERE INSTR_ROUTING_ID = #{irId, jdbcType=VARCHAR}
</select>
我能得到的只是一张空地图&#34; {}&#34;或例外,例如说它找不到类型&#34; java.util.HashMap&#34;。
有人能让我直截了当吗?这应该很容易......
答案 0 :(得分:0)
我有一个简化的版本。我将其更改为仅为给定的INSTR_INSTANCE_NM获取一个LAB_SYSTEM_NM(而不是加载整个表)。
<?xml version="1.0" encoding="UTF-8"?>
<select id="getDiInstanceName" resultType="String">
select LAB_SYSTEM_NM as destinationName
from INSTR_ROUTING
WHERE INSTR_INSTANCE_NM = #{instrumentName, jdbcType=VARCHAR}
</select>
public String getDiInstanceNameFor(String instrumentName) {
return getSqlSession().selectOne(NAMESPACE_PFX + "getDiInstanceName", instrumentName);
}
希望能帮助别人。