The 1.datasource interface is the interface under the Javax.sql package, not spring, which is the javax.sql
The DataSource interface has an important method getconnection () method
Connection getconnection (string Username, string password) throws SQLException;
Those spring-supported database connection pools are implemented with the DataSource interface
For example, the following is Ali's Druiddatasource database connection pool source code, it is the implementation of the DataSource Getconnection () method
As long as it is a class that implements this method, it can be the datasource of spring.
@Override Publicdruidpooledconnection getconnection () throws SQLException {returngetconnection (maxwait); } PublicDruidpooledconnection getconnection (LongMaxwaitmillis) throws SQLException {init (); if(Filters.size () >0) {Filterchainimpl Filterchain=NewFilterchainimpl ( This); returnFilterchain.datasource_connect ( This, Maxwaitmillis); } Else { returnGetconnectiondirect (Maxwaitmillis); } }
2.jdbcTemplate is the tool of spring, under the Springframework.jdbc bag
3. So spring if you want, you can also connect to the database itself, to execute SQL statements, not mybatis or hibernate.
Just use spring's own jdbctemplate, but there's no ORM match.
4. If you want to use MyBatis, hibernate them to connect to the database, it is necessary to use their similar jdbctemplate ah, such as MyBatis sqlsessiontemplate.
5. So in spring, to manipulate the database is divided into three steps: 1. Database, DataSource 2. Find a sharp weapon to manipulate the SQL language, JdbcTemplate or Sqlsessionfactory 3. Inject a sharp weapon into the spring IOC container
The core of 6.1.spring integrated MyBatis is Sqlsessionfactorybean, Mapperfactorybean (Single interface)
The core of 7.1.spring integrated MyBatis is Sqlsessionfactorybean, Mapperfactorybean (Single interface)
The core of 8.1.spring integrated MyBatis is Sqlsessionfactorybean, Mapperfactorybean (Single interface)
Several important classes and interfaces of spring