ibatis学习笔记(三)>>>>>>>java实体跟表映射.xml文件详解

时间:2022-12-25 18:41:12
在项目中使用Ibatis难免会使用到java实体跟表映射.xml.

 

<?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="ALARM_CAUSE" >
<typeAlias type="com.metarnet.ipnms.alarm.model.AlarmCause" alias="alarmCause"/> <!--
给实体类的一个别名,方面下文引用-->
  <resultMap id="AlarmCauseResult" class="alarmCause" >  <!-- javabean
跟数据库表列的映射
-->
    <result column="CAUSE_ID" property="causeId" jdbcType="DECIMAL" />
    <result column="CAUSE_NAME" property="causeName" jdbcType="VARCHAR" />
    <result column="CAUSE_NAME_CN" property="causeNameCn" jdbcType="VARCHAR" />
    <result column="ALARM_LEVEL" property="alarmLevel" />
    <result column="LEVEL_NAME" property="levelName" jdbcType="VARCHAR" />
    <result column="CAUSE_NAME_CN" property="causeNameCn" jdbcType="VARCHAR" />
    <result column="ALARM_DESC" property="alarmDesc" jdbcType="VARCHAR" />
    <result column="RESID" property="resid" jdbcType="VARCHAR" />
  </resultMap>

  <sql id="ALARM_CAUSE_Example_Where_Clause" ><!-- 动态的生成SQL -->
    <iterate property="oredCriteria" conjunction="or" prepend="where" removeFirstPrepend="iterate" >
      <isEqual property="oredCriteria[].valid" compareValue="true" >
        (
        <iterate prepend="and" property="oredCriteria[].criteriaWithoutValue" conjunction="and" >
          $oredCriteria[].criteriaWithoutValue[]$
        </iterate>
        <iterate prepend="and" property="oredCriteria[].criteriaWithSingleValue" conjunction="and" >
          $oredCriteria[].criteriaWithSingleValue[].condition$
            #oredCriteria[].criteriaWithSingleValue[].value#
        </iterate>
        <iterate prepend="and" property="oredCriteria[].criteriaWithListValue" conjunction="and" >
          $oredCriteria[].criteriaWithListValue[].condition$
          <iterate property="oredCriteria[].criteriaWithListValue[].values" open="(" close=")" conjunction="," >
            #oredCriteria[].criteriaWithListValue[].values[]#
          </iterate>
        </iterate>
        <iterate prepend="and" property="oredCriteria[].criteriaWithBetweenValue" conjunction="and" >
          $oredCriteria[].criteriaWithBetweenValue[].condition$
          #oredCriteria[].criteriaWithBetweenValue[].values[0]# and
          #oredCriteria[].criteriaWithBetweenValue[].values[1]#
        </iterate>
        )
      </isEqual>
    </iterate>
  </sql>

<!-- 查询语句标签返回一个结果集 如果返回多个结果集则用 resultMap 如果返回单个结果集则用resultClass="AlarmCauseResult" -->
  <select id="ALARM_CAUSE_selectAllAlarmCause" resultMap="AlarmCauseResult">
      <!--  select statement  -->

  </select>
    
  <!-- 
删除语句标签ibatis中默认的删除语句是返回数据库受影响的行数
 -->
  <delete id="ALARM_CAUSE_deleteByPrimaryKey" parameterClass="com.metarnet.ipnms.alarm.model.AlarmCause" >
            <!--  delete  statement  -->

  </delete>

   <!--新增语句标签返回数据库受影响的行数 -->
  <insert id="ALARM_CAUSE_insert" parameterClass="com.metarnet.ipnms.alarm.model.AlarmCause" >
   <!--  insertstatement  -->  </insert>

 

 <!--修改语句标签返回数据库受影响的行数 -->
  <update id="ALARM_CAUSE_updateByPrimaryKey" parameterClass="com.metarnet.ipnms.alarm.model.AlarmCause">

      <!-- update statement -->
     </update>

<procedure id="ALARM_CAUSE_getById" parameterMap="" >

    {? = call alarm.getSingleDetailRows(?)}

</procedure>

  </sqlMap>

java实体跟数据库表的映射到此结束了。