Ich habe das Buch und die Dokumentation über Mybatis gelesen, sowohl XML als auch Annotation tun, was ich will, aber von myBatis offizieller Website behaupten sie, XML sei ein besserer Weg Mappers zu machen, da Java Annotation Einschränkungen hat.Mybatis XML vs Annotation
Ich persönlich bevor Anmerkungen z
public interface PersonDAO {
String INSERT_PERSON = "insert into person (title,firstName,surName,jobTitle,dob,email,mobile,landPhone,fax,twitter,facebook,linkedin) VALUES (#{title},#{firstName},#{surName},#{jobTitle},#{dob},#{email},#{mobile},#{landPhone},#{fax},#{twitter},#{facebook},#{linkedin})";
String UPDATE_PERSON = "update person set title=#{title},firstName=#{firstName},surName=#{surName},jobTitle=#{jobTitle},dob=#{dob},email=#{email},mobile=#{mobile},landPhone=#{landPhone},fax=#{fax},twitter=#{twitter},facebook=#{facebook},linkedin=#{linkedin} where id=#{id}";
String GET_PERSON_BY_ID = "SELECT * FROM vw_person WHERE id = #{personId}";
String DELETE_PERSON = "DELETE FROM person WHERE id = #{personId}";
@Select(GET_PERSON_BY_ID)
public PersonVO doSelectPerson(long personId) throws Exception;
@Update(UPDATE_PERSON)@Options(flushCache = true, useCache = true)
public int doUpdatePerson(PersonVO vo) throws Exception;
@Insert(INSERT_PERSON)@Options(useGeneratedKeys = true, keyProperty = "id", flushCache = true)
public int doCreatePerson(PersonVO person) throws Exception;
@Delete(DELETE_PERSON)@Options(flushCache = true)
public int doDeletePerson(long personId) throws Exception;
}
Ich frage mich, was die Begrenzung ist? Nichts scheint mir offensichtlich zu sein.
Lesen Sie diesen Beitrag, um zu erfahren, welche Annotationen auf [Xml-Konfiguration versus Annotation-basierte Konfiguration] beschränkt sind (http://stackoverflow.com/a/183401/1793718). Soweit es myBatis betrifft, sagt die [Dokumentation] (https://mybatis.github.io/mybatis-3/getting-started.html), dass XML-Mapping immer noch für die fortgeschrittensten Zuordnungen benötigt wird. Ein Beispiel dafür ist die Verschachtelte Join-Zuordnung. – Lucky
Lesen Sie auch diese verwandte Frage zu [Mybatis-Annotationen in komplexen Anwendungen] (http://stackoverflow.com/questions/15352242/mybatis-annotations-in-complex-applications) – Lucky