私はこの問題がGoogleまたはスタックで非常に奇妙なものであると考えています。私に説明させてください。MyBatisのXML ResultMapでアソシエイティブ
私は自分のインタフェースメソッドの注釈に結果マップを持っています。この特定のケースでのみ私は動的なクエリが必要であり、それがxmlファイルのインタフェース用のマッパー全体を記述することに決めた理由です。以下は、ファイル全体を貼り付けます。選択したクエリは大丈夫ですが、<resultMap>
でいくつかの問題が発生しています。
私はさまざまなウェブサイトで、1対1、1対多、多対1の関連付け、およびこの結果マップの一般的な構成の良い説明を探していました。
私はサブクエリ、subresultmapsにいくつかの種類の可能性があることがわかりました。しかし、私はすでにmyBatisアノテーションを使っています。私はそれを使いたいと思います。 私に指示してください。結果マップをどのように構築する必要がありますか?私は、コンストラクタ、弁別のために必要な参照いけないが、それはまだ叫んでいます...(私は<collection>
マークを追加した理由です) - IntelliJのは言って全体<resultMap>
を強調している:"The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)"
私はそれが明白なようだけど、私はcompletly持っていますどのように正しくそれを行うか分かりません。私を助けてください。
XMLマッパーファイル:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="pl.net.manager.dao.UsageCounterDAO">
<select id="getUsageCounterList" resultType="pl.net.manager.domain.UsageCounter"
resultMap="getUsageCounterListMap">
SELECT * FROM usage_counter WHERE
<if test="apiConsumerIdsList != null">
api_consumer IN
<foreach item="item" index="index" collection="apiConsumerIdsList"
open="(" separator="," close=")">
#{item}
</foreach>
AND
</if>
<if test="serviceConsumerIdsList != null">
service IN
<foreach item="item" index="index" collection="serviceConsumerIdsList"
open="(" separator="," close=")">
#{item}
</foreach>
AND
</if>
<if test="dateFrom != null">
date >= #{dateFrom} AND
</if>
<if test="dateTo != null">
date <= #{dateTo} AND
</if>
<if test="status != null">
status = #{status}
</if>
</select>
<resultMap id="getUsageCounterListMap" type="">
ofType="pl.net.manager.domain.UsageCounter">
<id property="id" column="id"/>
<result property="date" column="date"/>
<result property="apiConsumer" column="api_consumer"
javaType="pl.net.manager.domain.ApiConsumer"/>
<association property="apiConsumer" column="api_consumer"
resultMap="pl.net.manager.dao.ApiConsumerDAO.getApiConsumer"/>
<result property="service" column="service" javaType="pl.net.manager.domain.Service"/>
<association property="service" column="service"
resultMap="pl.net.manager.dao.ServiceDAO.getService"/>
<result property="counterStatus" column="counter_status"/>
<result property="ratingProcessId" column="rating_process_id"/>
<result property="value" column="value"/>
<result property="createdDate" column="created_date"/>
<result property="modifiedDate" column="modified_date"/>
</resultMap>
</mapper>
'は'あなたがグループに必要があることを意味し、すべての '' タグ、 '' タグの後に来ると、その –
MohamedSanaulla