简体   繁体   中英

MyBatis - Mapper vs DAO

I am trying to get this answered, and found one comment in the MyBatis documentation:

Usually MapperFactoryBean is preferred to this class, since it requires no extra code. But, this class( DAO ) is useful if you need to do other non-MyBatis work in your DAO and concrete classes are required and use SqlSessionDaoSupport or SqlSessionFactory

In case I chose to use MapperFactoryBean today in my project, but later I would need to use concrete DAO (may be because you may not do 100% using SQLs in mapper), then I need to change the design.

If the above is true, then MapperFactoryBean would be very less useful and would never(or mostly) be a choice.

In other words: Can MapperFactoryBean and DAO co-exists? Even if yes, should they be?

Are you aware of what this "non-MyBatis work" or "some dynamic SQL" how you call it exactly is? Well I'm not. But assuming writing Mappers is much faster and more intuitive for your developers you are saving a lot of time here. And when there are some scary non-MyBatis things to do why not writing then a very specific DAO which only does this one non-MyBatis thing?

+1 for coexistence ( DAO is not a must ! ) This is especially true if you are using mybatis in spring framework.

As for the refactoring part, it's good if you have incorpoproate a suitable testing framework to help out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM