ibatis配置示例

创建SqlMapClient 对象的类

public class SqlConfig {
private static final SqlMapClient sqlMap;
static {
try {
String resource = "../sql-map-config.xml";
Reader reader = Resources.getResourceAsReader (resource);
sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException ("Error initializing MyAppSqlConfig class. Cause: " + e);
}
}
public static SqlMapClient getSqlMapInstance () {
return sqlMap;
}
}

sql-map-config.xml文件:
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">

<sqlMapConfig>

<properties resource="../database.properties"/>

<settings
cacheModelsEnabled="true"
enhancementEnabled="true"
lazyLoadingEnabled="true"
maxRequests="32"
maxSessions="10"
maxTransactions="5"
useStatementNamespaces="false"
/>
<!-- Type aliases allow you to use a shorter name for long fully qualified class names. -->
<typeAlias alias="order" type="testdomain.Order"/>
<!-- Configure a datasource to use with this SQL Map using SimpleDataSource.
Notice the use of the properties from the above resource -->
<transactionManager type="JDBC" >
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${driver}"/>
<property name="JDBC.ConnectionURL" value="${url}"/>
<property name="JDBC.Username" value="${username}"/>
<property name="JDBC.Password" value="${password}"/>
</dataSource>
</transactionManager>
<!-- Identify all SQL Map XML files to be loaded by this SQL map.
Notice the paths are relative to the classpath. -->
<sqlMap resource="com/globalzt/b2c/persistence/administration/sql/Goods.xml" />
<sqlMap resource="com/globalzt/b2c/persistence/administration/sql/Login.xml" />
<sqlMap resource="com/globalzt/b2c/persistence/administration/sql/GoodsBrand.xml" />
<sqlMap resource="com/globalzt/b2c/persistence/administration/sql/GoodsCategory.xml" />
<sqlMap resource="com/globalzt/b2c/persistence/administration/sql/Menu.xml" />
</sqlMapConfig>

database.properties文件:
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://192.168.1.112:3306/b2c?characterEncoding=utf-8
username=b2c
password=b2c
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值