mybatis的配置文件裏,主要是config和mapper。config定義了全局參數:數據源類型(POOL, UNPOOLED, JNDI)、事務管理類型(默認爲managed)、庫url、帳戶信息和mapper文件路徑。mysql
// config.xml <configuration> <environments default="classfly"> <environment id="classfly"> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/test?characterEncoding=utf-8" /> <property name="username" value="yourusername" /> <property name="password" value="yourpassword" /> </dataSource> </environment> </environments> <mappers> <mapper resource="mapper/UserMapper.xml" /> </mappers> </configuration>
DBNAME='test',是mybatis默認分配的庫:
sql
首先咱們要問本身如下三個問題:mybatis