• 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>
  • 相关阅读:
    tp5 查询问题 字段自增 字段比较
    七牛云 {"error":"no such domain"}
    mac 命令
    跟微信公众号一起来学api安全
    vue 运行别人项目
    php sha1withrsa
    thinkphp5 使用路由下分页 form表单 搜索
    P2134 百日旅行 (斜率优化,DP)
    [USACO Section 4.4]追查坏牛奶Pollutant Control (最小割)
    [HAOI2007] 理想的正方形 (单调队列)
  • 原文地址:https://www.cnblogs.com/ningJJ/p/7735679.html
Copyright © 2020-2023  润新知