ibatis配置文件的namespace

ibatis的配置文件中有一个命名空间的属性,如<sqlMap namespace="common">,默认情况下这个功能是关闭的。
要打开它需要在SqlMapConfig.xml文件中进行配置:
<sqlMapConfig>

<settings
cacheModelsEnabled="true"
enhancementEnabled="true"
lazyLoadingEnabled="true"
errorTracingEnabled="true"
maxRequests="32"
maxSessions="10"
maxTransactions="5"
useStatementNamespaces="true"
/>

......

</sqlMapConfig>

启用了命名空间后,我们用queryForXXX进行操作的时候就要加上命名空间了,即“命名空间名.ID名

******************************************************************

getSqlMapClientTemplate().update("namespace.id", new Integer(id));
A.xml

<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" 
    "http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="A">
    <update id="abcd">......</update>
</sqlMap>
B.xml

<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" 
    "http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="B">
    <select id="abcd">......</select>
</sqlMap>


两个sqlmap file都有id为"abcd"的配置,如果这种情况,我执行getSqlMapClientTemplate().update("abcd", new Integer(id));的时候,ibatis知道是调谁啊?

ibatis中有一个设置
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" 
    "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
    <settings 
        cacheModelsEnabled="true"
        lazyLoadingEnabled="false" 
        useStatementNamespaces="true" />


这儿的useStatementNamespaces="true"就是处理这个情况的,如果设为true(默认为false),你的调用就是
getSqlMapClientTemplate().update("namespace.id", new Integer(id));

猜你喜欢

转载自fhqllt.iteye.com/blog/1060799