日期:2014-05-16  浏览次数:20552 次

ibatis基本语法
<?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="User">
    	<typeAlias alias="page" type="byd.core.Page"/>
    	<typeAlias alias="user" type="byd.entity.User"/>
    	<parameterMap id="userMap" class="user">
    		<parameter property="userName" javaType="string" jdbcType="VARCHAR"/>
    		<parameter property="passWord" javaType="string" jdbcType="VARCHAR"/>
    		<parameter property="emplNo" javaType="string" jdbcType="VARCHAR"/>
    		<parameter property="emplName" javaType="string" jdbcType="VARCHAR"/>
    		<parameter property="phoneNum" javaType="string" jdbcType="VARCHAR"/>
    		<parameter property="email" javaType="string" jdbcType="VARCHAR"/>
    		<parameter property="deptName" javaType="string" jdbcType="VARCHAR"/>
    		<parameter property="dutyName" javaType="string" jdbcType="VARCHAR"/>
    		<parameter property="remark" javaType="string" jdbcType="VARCHAR"/>
    		<parameter property="companyName" javaType="string" jdbcType="VARCHAR"/>
    	</parameterMap>
    	<sql id="byUserIdCondition">
    		<![CDATA[
    			id = #id:INTEGER#
    		]]>
    	</sql>
    	<!-- 新增用户 -->
    	<insert id="save" parameterMap="userMap">
    		<![CDATA[
    			INSERT INTO PLAN_USER (id,userName,passWord,emplNo,emplName,phoneNum,email,deptName,dutyName,remark,companyName)
    			VALUES (PLAN_USER_LOG_S.nextval,?,?,?,?,?,?,?,?,?,?)
    		]]>
    		<selectKey resultClass="java.lang.Integer">
			<![CDATA[
				SELECT  PLAN_USER_LOG_S.currval
				AS id FROM dual
			]]>
		</selectKey>
		</insert>
		<!-- 删除用户 -->
		<delete id="deleteById" parameterClass="user">
			<![CDATA[
				delete PLAN_USER
			]]>
			<dynamic prepend="WHERE">
				<include refid="byUserIdCondition"/>
			</dynamic>
		</delete>
    	<!-- 修改用户 -->
    	<update id="update" parameterClass="user">
		<![CDATA[
			update PLAN_USER
		]]>
		<dynamic prepend="SET">
			<isNotNull property="userName" prepend=",">
				<![CDATA[
					userName = #userName#
				]]>
			</isNotNull>
			<isNotNull property="passWord" prepend=",">
				<![CDATA[
					passWord = #passWord#
				]]>
			</isNotNull>
			<isNotNull property="emplNo" prepend=",">
				<![CDATA[
					emplNo = #emplNo#
				]]>
			</isNotNull>
			<isNotNull property="emplName" prepend=",">
				<![CDATA[
					emplName = #emplName#
				]]> 
			</isNotNull>
			<isNotNull property="phoneNum" prepend=",">
				<![CDATA[
					phoneNum = #phoneNum#
				]]>
			</isNotNull>
			<isNotNull property="deptName" prepend=",">
				<![CDATA[
					deptName = #deptName#
				]]>
			</isNotNull>
			<isNotNull property="dutyName" prepend=",">
				<![CDATA[
					dutyName = #dutyName#
				]]>
			</isNotNull>
			<isNotNull property="remark" prepend=",">
				<![CDATA[
					remark = #remark#
				]]>
			</isNotNull>
			<isNotNull property="email" prepend=",">
				<![CDATA[
					email= #email#
				]]>
			</isNotNull>
			<isNotNull property="companyName" prepend=",">
				<![CDATA[
					companyName = #companyName#
				]]>
			</isNotNull>
		</dynamic>
		<dynamic prepend="WHERE">
			<include refid="byUserIdCondition" />
		</dynamic>
	</update>
	<!-- 分页查询 -->
	<select id="findByPage" parameterClass="page" resultClass="user">
		<![CDATA[
			SELECT id,userName,passWord,emplNo,emplName,phoneNum,email,deptName,dutyName,remark,companyName,state FROM (SELECT a.*,ROWNUM nm
			FROM (SELECT u.id, u.username, u.passWord, u.emplname, u.emplno, u.c