Spring provides good support for Ibatis through DAO mode. The Sqlmapclient object is the primary object in Ibatis, and we can configure it to let Spring manage the creation of Sqlmapclient objects.
Like Hibernate, Spring provides a Sqlmapclientdaosupport object, and our DAO can inherit this class and manipulate the database through the Sqlmapclienttemplate object it provides. It seems that these concepts are similar to hibernate.
There is no problem in manipulating the database's crud through Sqlmapclienttemplate, and the key issue here is transaction processing. Spring provides powerful declarative transactional capabilities, and we already know how to configure declarative transactions in Hibernate, so how can we get declarative transactions in Ibatis?
First, we need to understand that Spring uses AOP to intercept the invocation of methods, thus adding declarative transactional capabilities to these methods. The typical configuration is as follows: Applicationcontext-common.xml
These transactions are declared on the object of the business logic layer.
Second, we need a transaction manager to manage the transaction.
Thereafter, we need to let spring manage the Sqlmapclient object:
Our sqlmapconfig.xml can be abbreviated as:
User.xml: The following:
The writing of my DAO:
Inheriting the sqlmapclientdaosupport requires us to inject the Sqlmapclient object, so the following DAO configuration is required:
That's all you need to be aware of, and then you can invoke the DAO object at the business logic level!
Spring and Ibatis Integration