Database connection configuration
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mybatis"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
</dataSource>
</environment>
</environments>
</configuration>
In the above example, we defined an development
environment named using the JDBC transaction manager and the POOLED data source. Among them, driver
, url
, username
and password
specify the database connection driver, connection URL, user name and password respectively.
Mapper configuration
<configuration>
<mappers>
<mapper resource="com/example/mapper/UserMapper.xml"/>
<mapper class="com.example.mapper.OrderMapper"/>
</mappers>
</configuration>
In the above example, we defined two mappers, namely com.example.mapper.UserMapper.xml
and com.example.mapper.OrderMapper
. Among them, resource
the attribute specifies the path to the XML mapping file, and class
the attribute specifies the fully qualified name of the Java interface.
Global configuration
<configuration>
<settings>
<setting name="cacheEnabled" value="true"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="multipleResultSetsEnabled" value="true"/>
<setting name="useColumnLabel" value="true"/>
<setting name="defaultExecutorType" value="SIMPLE"/>
<setting name="defaultStatementTimeout" value="25000"/>
<setting name="defaultFetchSize" value="100"/>
</settings>
</configuration>
In the above example, we defined some global configurations, including caching on, lazy loading on, allowing multiple result sets, using column labels, default executor type, default statement timeout, and default result set size.