ibatis 的一个小例子
?
而在sqlmap中$是用来替换变量的
?
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
?<sqlMap namespace="com.soft.dao">
?<typeAlias alias="user" type="com.soft.model.User"/>
?<resultMap? id="ResultMap" property="id" jdbcType="VARCHAR"/>
??? <result column="username" property="userName" jdbcType="VARCHAR"/>
??? <result column="password" property="passWord" jdbcType="VARCHAR"/>
?</resultMap>
?
?? <!-- 查询方法 -->
? <select id="selectUserById" resultMap="ResultMap" parameterresultMap="ResultMap" parameterprepend="AND">
????????? id = #id:VARCHAR#
???? </isNotNull>
???? <isNotNull property="userName" prepend="AND">
???????? username = #userName:VARCHAR#
???? </isNotNull>
???? <isNotNull property="passWord" prepend="AND">
??????? password = #passWord:VARCHAR#
???? </isNotNull>
? </select>
????
?<!-- 插入方法 -->
?<insert id="inserUser" parameterparameterparameterproperty="username">
?????? username = #username:VARCHAR#
??? </isNotNull>
??? <isNotNull prepend="," property="password">
?????? password= #password:VARCHAR#
??? </isNotNull>
??? </dynamic>
??? where id=#id:INTEGER#
?</update>
?
?<update id="updateUser" parameterClass="user">
???? update t_sys_user
??????? set
??????????? username = #username:VARCHAR#,
??????????? password = #password:VARCHAR#
???? where? id = #id:INTEGER#
?</update>
</sqlMap>