ibatis简单使用
1.创建配置文件,数据库连接xml,实体xml,configuration.xml
configuration.xml文件如下
<sqlMapConfig>
<properties resource="com/zyt/comm/ibatis/dbconfig.properties"/><!--连接数据库信息-->
<settings
cacheModelsEnabled="true"
errorTracingEnabled="true"
enhancementEnabled="true"
lazyLoadingEnabled="true"
maxRequests="32"
maxSessions="10"
maxTransactions="5"
useStatementNamespaces="true"/>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${dirver}"/><!--根据dbconfig.properties文件自动匹配-->
<property name="JDBC.ConnectionURL" value="${url}"/>
<property name="JDBC.Username" value="${username}"/>
<property name="JDBC.Password" value="${password}"/>
</dataSource>
</transactionManager>
<sqlMap resource="com/zyt/comm/ibatis/user.xml"/><!--对象映射实体类-->
</sqlMapConfig>
dbconfig.properties文件内容如下
dirver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/zytcomdb
username=root
password=sa
user.xml文件跟Hibernate差不多对象映射文件