Mybatis傳遞參數的三種方式


第一種:

Dao層使用@Param注解的方法

VersionBox getVersionByVersionNumAndVersionType(@Param("versionNum") String versionNum, @Param("versionType") String versionType);

對應的Mapper.xml

 <sql id="Base_Column_List" >
    UUID, VERSION_NUM, VERSION_TYPE, VARSION_DESC, CREATE_TIME, CREATE_BY, UPDATE_TIME, 
    UPDATE_BY
  </sql>

  <select id="getVersionByVersionNumAndVersionType" resultMap="BaseResultMap" >
    select 
    <include refid="Base_Column_List" />
    from VERSION_BOX
    where VERSION_NUM = #{versionNum,jdbcType=VARCHAR} 
    and VERSION_TYPE = #{versionType,jdbcType=VARCHAR} 
  </select>

第二種:

Dao層采用Map傳多參數的方法

int selectBeaconTotalCount(Map paramMap);
 

對應的Mapper.xml

<resultMap id="BaseResultMap" type="com.joysuch.facade.device.Ibeacon" >
<id column="UUID" property="uuid" jdbcType="VARCHAR" />
<result column="USER_ID" property="userId" jdbcType="VARCHAR" />
<result column="DEVICE_MAC" property="deviceMac" jdbcType="VARCHAR" />
<result column="DEVICE_ID" property="deviceId" jdbcType="VARCHAR" />
<result column="DEVICE_UUID" property="deviceUuid" jdbcType="VARCHAR" />
<result column="DEVICE_TYPE" property="deviceType" jdbcType="VARCHAR" />
<result column="MAJOR" property="major" jdbcType="INTEGER" />
<result column="MINOR" property="minor" jdbcType="INTEGER" />
...

<result column="NEAR_RSSI" property="nearRssi" jdbcType="INTEGER" />
</resultMap>

 


<select id="selectBeaconTotalCount" resultType="int" parameterType="java.util.Map" > select COUNT(UUID) from IBEACON where BUILDING_ID = #{buildingId,jdbcType=VARCHAR} and DEVICE_TYPE = 'ibeacon' <if test="deviceMac != null and deviceMac != ''" > and DEVICE_MAC = #{deviceMac,jdbcType=VARCHAR} </if> <if test="major != null" > and MAJOR = #{major,jdbcType=INTEGER} </if> <if test="minor != null" > and MINOR = #{minor,jdbcType=INTEGER} </if> </select>

第三種:

Dao層根據參數位置下標的方法

VersionBox getVersionByVersionNumAndVersionType(String versionNum, String versionType);

  

對應的Mapper.xml

 <select id="getVersionByVersionNumAndVersionType" resultMap="BaseResultMap" >
    select 
    <include refid="Base_Column_List" />
    from VERSION_BOX
    where VERSION_NUM = #{0} 
    and VERSION_TYPE = #{1} 
  </select>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM