qshpeng 2012-05-28
核心配置文件:
----------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC"-//ibatis.apache.org//DTDSQLMapConfig2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd"><sqlMapConfig>
<!-- <properties resource="SqlMap.properties"/> -->
<!--Configureabuilt-intransactionmanager.Ifyou'reusingan
appserver,youprobablywanttouseitstransactionmanager
andamanageddatasource-->
<!--
<transactionManagertype="JDBC"commitRequired="false">
<dataSourcetype="SIMPLE">
<propertyname="JDBC.Driver"value="${driver}"/>
<propertyname="JDBC.ConnectionURL"value="${url}"/>
<propertyname="JDBC.Username"value="${username}"/>
<propertyname="JDBC.Password"value="${password}"/>
</dataSource>
</transactionManager>
-->
<!--ListtheSQLMapXMLfiles.Theycanbeloadedfromthe
classpath,astheyarehere(com.domain.data...)-->
<sqlMapresource="com/ibatis/model/Account.xml"/>
<!--Listmorehere...
<sqlMapresource="com/mydomain/data/Order.xml"/>
<sqlMapresource="com/mydomain/data/Documents.xml"/>
--></sqlMapConfig>
----------------------------------------------------------
实体类的映射文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC"-//ibatis.apache.org//DTDSQLMap2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd"><sqlMap namespace="Account">
<!-- Use type aliases to avoid typing the full classname every time. --> <!-- <typeAlias alias="Account" type="com.ibatis.model.Account"/> -->
</sqlMap>
如:对于sql语句order by #user_id#,如果传入的值是111,那么解析成sql时的值为order by "111", 如果传入的值是id,则解析成的sql为order by "id"。