The mybatis configuration file in MyBatis framework is described in detail

  • 2021-01-03 20:55:43
  • OfStack

1. Register the DB connection 4 element properties file


<propertiesresource="jdbc.properties"/>

2. Use the simple class names of all classes in the specified package as their aliases


<typeAliases>
   <packagename="com.bjpowernode.beans"/>
</typeAliases>

3. Configure the running environment


<environmentsdefault="testEM">
   <environmentid="testEM">
     <transactionManagertype="JDBC"/>
     <dataSourcetype="POOLED">
      <propertyname="driver" value="${jdbc.driver}"/>
      <propertyname="url" value="${jdbc.url}"/>
      <propertyname="username" value="${jdbc.user}"/>
      <propertyname="password" value="${jdbc.password}"/>
     </dataSource>
   </environment>
  </environments>

Note: Different database links can be placed in environments. default specifies which one to use in the end. It is more convenient to change the database

transactionManager: Specifies business management, using JDBC's business management here

dataSource: Specify the data source, where the database connection pool is used

property: put links in the database need 4 elements, driver, url, username, password;

4. Register the mapping file


<mappers>   <mapperresource="com/bjpowernode/dao/mapper.xml"/>
</mappers>

Note: resource specifies which mapping file to register

conclusion


Related articles: