IBATIS

<sql id="isReported_where">
    <dynamic prepend="where">
        <isNotEmpty prepend=" " property="FPROVLEVELLIMIT">
            x1.FPROVLEVELLIMIT=#FPROVLEVELLIMIT#
        </isNotEmpty>
        <isNotEmpty prepend="and" property="FCOUNLEVELLIMIT">
            x1.FCOUNLEVELLIMIT=#FCOUNLEVELLIMIT#
        </isNotEmpty>
        <isNotEmpty prepend="and" property="FTOWNLEVELLIMIT">
            x1.FTOWNLEVELLIMIT=#FTOWNLEVELLIMIT#
        </isNotEmpty>
        <isNotEmpty prepend="and" property="FVILLLEVELLIMIT">
            x1.FVILLLEVELLIMIT=#FVILLLEVELLIMIT#
        </isNotEmpty>
    </dynamic>
</sql>

        <isNotEmpty prepend=””
property=””></isNotEmpty>

<insert id="insertTSORGDIAITEM" parameterClass="map">
    INSERT INTO 表名
</insert>

    举例:

        <isEqual prepend=”” property=””
compareValue=””></isEqual>

  (四)IBATIS + ORACLE

      语法:

    UpdateTime–2017年6月15日08:15:36

      举例:

<insert id="insertTDOCTORORG" parameterClass="map">
  <selectKey keyProperty="FID" resultClass="java.lang.Long">
    SELECT SEQ_1.NEXTVAL FROM DUAL
  </selectKey>
  INSERT INTO TDOCTORORG
    (FID,
     FDOCTORCODE,
     FDOCTORNAME,
     FZJM,
     FRCODE,
     FORGID,
     FDOCTORCODE_CENTER,
     FREMARK,
     FDEPTCODE)
  VALUES
    (#FID#,
     #FDOCTORCODE#,
     #FDOCTORNAME#,
     #FZJM#,
     #FRCODE#,
     #FORGID#,
     #FDOCTORCODE_CENTER#,
     #FREMARK#,
     #FDEPTCODE#)
</insert>

    1.3.4 查

<!-- 引用通用SQL -->
<include refid="TSORGDIAITEM_WHERE"/>      

        若parameterClass中不设有参数,如:FDOCTORCODE_CENTER,iBATIS举办ORM映射时,会活动将该字段对应的值置为NULL,执行该SQL时不会生出尤其;

<update id="updateTDICTICDCODE"  parameterClass="map">
    UPDATE 表名
</update>
<sqlMapConfig>
    <settings cacheModelsEnabled="true" lazyLoadingEnabled="true"
        enhancementEnabled="true" useStatementNamespaces="true"
        statementCachingEnabled="true" classInfoCacheEnabled="true" />
</sqlMapConfig>

  iBATIS一词来源于“internet”和“abatis”的三结合,是一个由ClintonBegin在2002年倡议的绽开源代码项目。于二〇一〇年二月16号被谷歌托管,改名为MyBatis。是一个基于SQL映射匡助Java和·NET的持久层框架。

<isNotEmpty property="CLICOM" >
     order by A.FCLINHITS DESC,length(A.FZJM) ASC,FICDCODE 
</isNotEmpty>
<isEmpty property="CLICOM">
    <isNotEmpty property="HOSCOM" >
        order by A.FINHOSHITS DESC,length(A.FZJM) ASC,FICDCODE
    </isNotEmpty>
    <isEmpty property="HOSCOM">
        order by A.FINHOSHITS DESC,length(A.FZJM) ASC,FICDCODE
    </isEmpty>
</isEmpty>

      大于用 > 表示,小于用 < 表示

    UpdateTime–2017年8月8日09:08:03

    方法一:      

    转换成SQL

        若parameterClass中存在参数,如:FDOCTORCODE_CENTER,但相应的值为空,iBATIS举行ORM映射时,会活动将该字段对应的值置为空字符串””。

  (一)配置

    1.2.8 关于prepend

<update id="updateFDOCTORCODE" parameterClass="map">
    UPDATE TDOCTORORG
       SET FDOCTORCODE_CENTER = #FDOCTORCODE_CENTER#,
           FDOCTORNAME        = #FDOCTORNAME#,
           FZJM               = #FZJM#,
           FDEPTCODE          = #FDEPTCODE#
     WHERE FDOCTORCODE = #FDOCTORCODE#
       AND FRCODE = #FRCODE#
       AND FORGID = #FORGID#
</update>
INSERT INTO TDOCTORORG
  (FID,
   FDOCTORCODE,
   FDOCTORNAME,
   FZJM,
   FRCODE,
   FORGID,
   FDOCTORCODE_CENTER,
   FREMARK,
   FDEPTCODE)
VALUES
  (?, ?, ?, ?, ?, ?, ?, ?, ?)
--[142929, 001, test, 001, 410122, 0, , null, null]

    见其余两篇文章     

  (三)常用操作

      注意:

  (二)常用标签    

    iBATIS的isNotNull和isNotEmpty的区别

if(FREMARK){
    FREMARK = #FREMARK#
}
<isNotNull prepend="," property="FJCMYEAR">
    FJCMYEAR=#FJCMYEAR#
</isNotNull>

      语法:

      举例:

   CreateTime–2016年12月9日17:45:21

        a.dynamic
prepend=”值”,那么些地点的值视意况而定,一般为””或”where”;

<isEqual prepend="and" property="FCOMLVL" compareValue="-1">
    FCOMLVL IS NULL
</isEqual>

CreateTime–2017年5月29日13:56:15
Author:Marydon

    1.3.2 改

      语法:

      第二步:引用引用SQL

      前台传过来的字段中不仅要包罗FREMARK,并且FREMARK的始末不可以为空,才会实施

    举例:

      2.使用TO_CHAR(),TO_DATE()等函数时千万别忘了给该字段起别名!

        <isNull prepend=””
property=””></isNull>    

<isNotEmpty prepend="and" property="FICDFM">
    FICDFM=#FICDFM#
</isNotEmpty>
<isNotNull prepend="," property="FREMARK">
    FREMARK = #FREMARK#
</isNotNull>
<isNotEmpty prepend="," property="FBEGINDATE">
    FBEGINDATE = TO_DATE(#FBEGINDATE#,'yyyy-MM-dd')
</isNotEmpty>

    转换成SQL

  

      isNotNull相当于

    1.2.1 字段不等于实际的值:column==”value”  

    方法二:

      举例:        

    举例:

    1.2.2 字段等于实际的值:column!=”value”

    1.2.3 字段不为空:column!=null  

一、IBATIS

    1.1.1 ibatis配置文件常用配置

    1.2.4 字段非空且不是空字符串:column!=null && column!=””

    注意:

UPDATE TDOCTORORG
   SET FDOCTORCODE        = ?,
       FDOCTORCODE_CENTER = ?,
       FDOCTORNAME        = ?,
       FZJM               = ?,
       FDEPTCODE          = ?
 WHERE FID = ?
   AND FRCODE = ?
   AND FORGID = ?
--[001, , test1, 001, null, 142929, 410122, 0]

    1.3.3 删

MyBatis,      语法:

     参数表明:

    举例:

      ]]>

    1.3.5 动态拼接WHERE查询条件

<?xml version="1.0" encoding="UTF-8"?>
<!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 cacheModelsEnabled="true" errorTracingEnabled="true"
        enhancementEnabled="true" lazyLoadingEnabled="true" maxRequests="512"
        maxSessions="384" maxTransactions="256" useStatementNamespaces="true" />

    <!-- 
        特别注意:只能直接引用SQLMap文件,不能通过:引用子配置文件,子配置文件去引用SQLMap文件的方式实现,
        否则,最终会找不到SQLMap文件
    -->        
    <!-- 患者信息 -->
    <sqlMap resource="telemedicine/service/domain/entites/oracle/patient/PATIENT_INFO.xml" />


</sqlMapConfig>
SELECT T1.PATIENT_NAME,
         T1.SEX,
         T1.BIRTH_DAY,
         T1.OUTPAT_CODE,
         TO_CHAR(T2.CONSULT_DATE, 'yyyy-MM-dd HH24:mi') CONSULT_DATE,
         T2.CONSULT_CLASS,
         T2.CONSULT_TYPE,
         T3.CONSULT_DIAGNOSIS,
         T3.TREATMENT_PLAN,
         T3.REMARK,
         T3.CONSULT_PEOPLE
    FROM OUTPATIENT_INFO                T1,
         OUTPATIENT_CONSULT_INFO        T2,
         OUTPATIENT_CONS_ASSESSMENTINFO T3
   WHERE T1.PATIENT_INFO_ID = ?
     AND T2.CONSULT_APPLY_ID = ?
     AND T1.PATIENT_INFO_ID = T2.PATIENT_INFO_ID
     AND T2.CONSULT_APPLY_ID = T3.CONSULT_APPLY_ID
--[51CE27E4269418A9E0530100007FCD14, 51CE27E4269518A9E0530100007FCD14]    

    1.2.5 字段存在,且为空:column!=null&&column==””

    1.1.2 ibatis的总布局有且不得不有一个,总布局文件直接引用种种SQLMap文件,不可能像struts一样,a总计划文件–>引用b子配置文件–>…n层–>各类配置文件。

      1.运用iBATIS举行增、改操作时,parameterClass映射到SQL时:

    以<isNotNull prepend=”and” property=”firstName”>为例

if(FREMARK != null && FREMARK != ""){
    FREMARK = #FREMARK#
}

      语法:

<isNotEqual prepend="and" property="FPLVCODE" compareValue="1">
    FPLVCODE=#FPLVCODE#
</isNotEqual>

        <isEmpty prepend=”” property=””></isEmpty>

<select id="getPrint" resultClass="map">
  SELECT T1.PATIENT_NAME,
         T1.SEX,
         T1.BIRTH_DAY,
         T1.OUTPAT_CODE,
         TO_CHAR(T2.CONSULT_DATE, 'yyyy-MM-dd HH24:mi') CONSULT_DATE,
         T2.CONSULT_CLASS,
         T2.CONSULT_TYPE,
         T3.CONSULT_DIAGNOSIS,
         T3.TREATMENT_PLAN,
         T3.REMARK,
         T3.CONSULT_PEOPLE
    FROM OUTPATIENT_INFO                T1,
         OUTPATIENT_CONSULT_INFO        T2,
         OUTPATIENT_CONS_ASSESSMENTINFO T3
   WHERE T1.PATIENT_INFO_ID = #PATIENT_INFO_ID#
     AND T2.CONSULT_APPLY_ID = #CONSULT_APPLY_ID#
     AND T1.PATIENT_INFO_ID = T2.PATIENT_INFO_ID
     AND T2.CONSULT_APPLY_ID = T3.CONSULT_APPLY_ID
</select>

      举例:

  

<delete id="delTSORGDIAITEM" parameterClass="map">
    DELETE FROM 表名
</delete>

      语法:

        <isNotEqual prepend=”” property=””
compareValue=””></isNotEqual>

        b.isNotEmpty
首个prepend的值为” “或”and”,必须有值。

cacheModelsEnabled
//是否启动ibatis中的缓存功能;
lazyLoadingEnabled
//是否同时懒加载带来极大的性能提升;
useStatementNamespaces
//是否使用 domain xml 文件中 namespace 别名配置
//iBATIS的默认是不会启动命名空间的,若使用,需声明该值为true
enhancementEnabled
//是否需要POJO启动Java字节码增强功能,可以提升getter/setter的调用效能避免Java反射所带来的性能开销。
剩下两个默认值都为true
classInfoCacheEnabled 
/*With this setting enabled, iBATIS will maintain a cache of introspected classes. This will lead to a  significant reduction in startup time if many classes are reused.*/
statementCachingEnabled (iBATIS 2.3.0以后版本中有)
/*With this setting enabled, iBATIS will maintain a local cache of prepared statements. This can lead to significant performance improvements.*/   

    举例:

 

        <isNotNull prepend=””
property=””></isNotNull>

      该字段内容可以为空,即FREMARK=

    1.3.1 增

      举例:  

    1.2.7 XML文本中什么运用”>”和”<“

<![CDATA[
      X1.ORGDEGREE <= #ORGDEGREE_Z#
]]>

      使用
      <![CDATA[

 

      第一步:表明动态WHERE条件

    UpdateTime–2017年1月22日15:15:03

    生成的语句不会有盈余的and,因为dynamic有一个隐藏的性质:removeFirstPrepend=”true”,
所以一般要写上prepend=”and”,需求的时候它会自动去掉。 

    1.2.6 字段不存在:column==null

<select id="getTSORGDIAITEM" parameterClass="map" remapResults="true" resultClass="java.util.HashMap" cacheModel="cacheTSORGDIAITEM">
    SELECT 字段 FROM 表名
</select>

      isNotEmpty相当于  

    转换成SQL

网站地图xml地图