myBatis project configuration

Keywords: JDBC Mybatis Database xml

myBatis project configuration

1,environment
Mybatis supports multiple environments and can be configured arbitrarily
2,transactionManager
Mybatis supports two types of transaction managers, JDBC and MANAGED (hosting)
JDBC: The application is responsible for managing the life cycle of database connections
MANAGED: The application server is responsible for managing the life cycle of the database connection; (This is the function of a general commercial server, such as JBOSS, WebLogic)
3,DataSource
Used to configure data sources, types are: UNPOOLED, POOLED, JNDI
UNPOOLED: No connection pool. Every database operation, mybatis creates a new connection and closes it after use. It is suitable for small concurrent projects.
POOLED: Connection pool used
JNDI: Configuring JNDI data sources to obtain data connections using application servers
4,property
Configuration properties
5,typeAliases
Aliases the fully qualified name of the class for easy use
6,mappers
Reference Profile
7. Configure log4j logs

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
	<properties resource="jdbc.properties"/> 
	<properties>
		<property name="jdbc.driverClassName" value="com.mysql.jdbc.Driver"/>
		<property name="jdbc.url" value="jdbc:mysql://localhost:3306/db_mybatis"/>
		<property name="jdbc.username" value="root"/>
		<property name="jdbc.password" value="123456"/>
	</properties>
	 <typeAliases>
		<typeAlias alias="Student" type="com.model.Student"/>
	</typeAliases> 
	<typeAliases>
		<package name="com.model"/>
	</typeAliases>
	<environments default="development">
		<environment id="development">
			<transactionManager type="JDBC" />
			<dataSource type="POOLED">
				<property name="driver" value="${jdbc.driverClassName}" />
				<property name="url" value="${jdbc.url}" />
				<property name="username" value="${jdbc.username}" />
				<property name="password" value="${jdbc.password}" />
			</dataSource>
		</environment>
		<environment id="test">
			<transactionManager type="JDBC" />
			<dataSource type="POOLED">
				<property name="driver" value="${jdbc.driverClassName}" />
				<property name="url" value="${jdbc.url}" />
				<property name="username" value="${jdbc.username}" />
				<property name="password" value="${jdbc.password}" />
			</dataSource>
		</environment>
	</environments>
	<mappers>
		 <mapper resource="com/mappers/StudentMapper.xml" /> 
		<mapper class="com.mappers.StudentMapper"/> 
		<package name="com.mappers"/>
	</mappers>
</configuration>

Posted by pixelgirl on Tue, 01 Oct 2019 17:48:43 -0700