Tôi đã đọc sách và tài liệu về Mybatis, cả XML và chú thích đều làm những gì tôi muốn, nhưng từ trang web chính thức của myBatis, họ tuyên bố XML là một cách tốt hơn để làm Mappers, bởi vì chú thích Java có những hạn chế.Mybatis XML vs Annotation
Cá nhân tôi thích Chú thích ví dụ
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;
}
Tôi tự hỏi những gì mà giới hạn là gì? Không có gì có vẻ hiển nhiên với tôi.
Đọc bài đăng này để nhận những chú thích được giới hạn đối với [cấu hình Xml so với cấu hình dựa trên chú thích] (http://stackoverflow.com/a/183401/1793718). Theo như myBatis có liên quan đến [tài liệu nói] (https://mybatis.github.io/mybatis-3/getting-started.html) rằng ánh xạ XML vẫn được yêu cầu cho các ánh xạ tiên tiến nhất. 'Nested Join Mapping' là một ví dụ về điều đó. – Lucky
Cũng đọc câu hỏi liên quan này về [Chú giải Mybatis trong các ứng dụng phức tạp] (http://stackoverflow.com/questions/15352242/mybatis-annotations-in-complex-applications) – Lucky