如何通過<include/>標籤重用Mybatis的程式碼段
1、首先定義一個sql標籤,一定要定義唯一id<sql id="Base_Column_List" >name,age</sql>
2、然後通過id引用
<select id="selectAll">
select
<include refid="Base_Column_List" />
from student
</select>
這個<include refid="Base_Column_List" />會自動把上面的程式碼貼過來。
例子:
<sql id="allColumn"> ID as id, SPARTICIPANTBANKNO as sParticipantBankNO, SPARTICIPANTFULLNAME as sParticipantFullName, SPHONE as sPhone, SADDRESS as sAddress </sql> <select id="queryCNAPSInfoByCondition" resultType="com.pcitc.ebank.query.entity.CNAPSInfo"> SELECT * FROM (SELECT A.*, ROWNUM RN FROM ( SELECT <include refid='allColumn'/> FROM BASE_BANK_INFO WHERE 1=1 <if test="sparticipantbankno != null"> AND sparticipantbankno like '%'||#{sparticipantbankno}||'%' </if> <if test="sparticipantfullname != null"> AND sparticipantfullname like '%'||#{sparticipantfullname}||'%' </if> ) A WHERE ROWNUM <= #{endindex}) WHERE RN >= #{startindex} </select>