【Mybatis】Global configuration file

 1. mybatis can use properties to introduce the content of the external properties configuration file

  resource: import resources under the classpath

 url: Introduce resources under the network path or disk path


<properties resource="dbconfig.properties"/>

2.settings contains many important settings

 setting: used to set each setting item

 name: set item name

value: the value of the setting item


<settings>
	<setting name="mapUnderscoreToCamelCase" value="true" />
</settings>


3.typeAliases: Aliases processor: can alias our Java types

  typeAlias: Aliasing a Java type Aliases are not case-sensitive

  type: Specify the full class name of the category to be aliased; the default alias is the lowercase class name


<typeAliases>
     <typeAlias type= "com.atguigu.mybatis.bean.Employee" alias="emp"/>
</typeAliases>

package: batch aliases for all classes under a certain report

 name: Specify the package name (a default alias (class name lowercase) is assigned to each class of the current package and all descendant packages below)


<typeAliases>
      <package name="com.atguigu.mybatis.bean"/>
</typeAliases>

In the case of batch aliasing, use the @Alias ​​annotation to specify a new alias for a type


 4.environments: Environments, mybatis can configure a variety of environments, the default specifies a certain environment, which can quickly switch the environment . Environment : To configure a specific environment information, there must be two labels; id represents the unique identifier of the current environment

transactionManager : transaction manager

type: the type of transaction manager

dataSource: data source

 type: data source type

 

As follows: To switch the test environment and the development environment, just change the default .


<environments default="test">
		<environment id="test">
			<transactionManager type="JDBC" />
			<dataSource type="POOLED">
				<property name="driver" value="${jdbc.driver}" />
				<property name="url" value="${jdbc.url}" />
				<property name="username" value="${jdbc.username}" />
				<property name="password" value="${jdbc.password}" />
			</dataSource>
		</environment>

		<environment id="development">
			<transactionManager type="JDBC" />
			<dataSource type="POOLED">
				<property name="driver" value="${jdbc.driver}" />
				<property name="url" value="${jdbc.url}" />
				<property name="username" value="${jdbc.username}" />
				<property name="password" value="${jdbc.password}" />
			</dataSource>
		</environment>
</environments>

 5. databaseIdProvider:支持多数据库厂商的 type=“DB_VENDOR”VendorDatabaseIDProvider

作用就是得到数据库厂商的标识(驱动getDatabaseProductName())mybatis就能根据数据库厂商处标识 来执行不同的SQL MySQLOracleSQL Serverxxx


<databaseIdProvider type="DB_VENDOR">
		<!-- 为不同的数据库厂商起别名 -->
		<property name="MySQL" value="mysql"></property>
</databaseIdProvider>

 

6.mappers:SQL映射注册到全局配置中

<mappers>
		<!-- mapper : 注册一个SQL映射 resource:引用类路径下的SQL映射文件 url:引用网络路径或者磁盘路径下的SQL映射文件 
			file:///var/mappers/AutorMapper.xml 
			注册接口: class:引用(注册)接口: 1.有SQL映射文件,映射文件名必须和接口同名,并且放在与接口同一目录下 
			
			2.没有SQL映射文件,所有的SQL都是利用注解写在接口上 
			推荐: 比较重要的,复杂的Dao接口写在SQL映射文件 不重要的,简单的Dao接口为了开发快速可以使用注解 -->
		<mapper resource="mybatis/mapper/EmployeeMapper.xml"/>    
		<!-- <mapper class="com.atguigu.mybatis.dao.EmployeeMapper"/> -->
	</mappers>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325727800&siteId=291194637