Ich habe eine select in mapper.xml-Datei definiert:Mybatis @Select Referenzierung wählen in Mapper XML-Datei definiert
<mapper namespace="foo">
<select id="selectWithRoles" parameterType="String" resultMap="personWithRoles">
select *
from
PERSON P
left outer join PERSON_ROLE R on P.ID = R.PERSON_ID
where P.ID = #{id}
</select>
<resultMap id="personWithRoles" type="Person">
<id property="id" column="ID" />
<collection property="roles" ofType="Role">
<id property="personId" column="PERSON_ID"/>
<result property="name" column="NAME"/>
</collection>
</resultMap>
</mapper>
und ich möchte diese Auswahl über DAO-Schnittstelle durch Anmerkung belichten (n) ohne das Kopieren select-Anweisungen in DAO. Im Anschluss funktioniert:
@Select("select * from PERSON P left outer join PERSON_ROLE R on P.ID = R.PERSON_ID where P.ID = #{id}")
@ResultMap("personWithRoles")
public Person loadByIdWithRoles(String id);
Aber Ich mag nicht SQL in Annotation Kopieren (könnte ziemlich lang sein) möchte etwas wie folgt aus:
@Select("selectWithRoles")
public Person loadByIdWithRoles(String id);
wo "selectWithRoles" ist id ausgesuchter definiert in XML . Ist es möglich?
Das ist genau das, was ich suchte. Danke vielmals! – codematix