ibatis 配置文件 SqlMapConfig&SqlMap 示例

#######################SqlMapConfig#######################

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

<sqlMapConfig>
<settings
useStatementNamespaces="true"
/>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL" value="jdbc:mysql://127.0.0.1:3306/orclight" />
<property name="JDBC.Username" value="root"/>
<property name="JDBC.Password" value="1234"/>
</dataSource>
</transactionManager>
<sqlMap resource="com/buct/sqlmap/user.ibatis.xml"/>
<sqlMap resource="com/buct/sqlmap/notebook.ibatis.xml"/>
</sqlMapConfig>


#######################SqlMap#######################

<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="NotebookDao">
<typeAlias alias="notebook" type="com.buct.model.Notebook" />

<insert id="insertNotebook" parameterClass="notebook">
<![CDATA[
insert into t_notebook(
id,
cpu,
ram,
logo,
price)
values(
#id#,
#cpu#,
#ram#,
#logo#,
#price#)
]]>
</insert>

<delete id="deleteNotebook" parameterClass="notebook">
<![CDATA[
delete from t_notebook where id = #id#
]]>
</delete>

<update id="updateNotebook" parameterClass="notebook">
<![CDATA[
update t_notebook set
cpu = #cpu#,
ram = #ram#,
logo = #logo#,
price = #price#
where id = #id#
]]>
</update>


<select id="selectNotebook" resultClass="notebook">
<![CDATA[
select * from t_notebook
]]>
</select>

<select id="selectNotebookCount" resultClass="int">

select count(*) from t_notebook

</select>


</sqlMap>

#############################测试代码################################

Reader reader = Resources.getResourceAsReader("sqlMapConfig.xml");
SqlMapClient sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
result = (Integer)sqlMapClient.queryForObject("NotebookDao.selectNotebookCount", filterMap);



你可能感兴趣的:(ibatis)