在MyBatis的select、insert、update、delete这些元素中都提到了parameterType这个属性。MyBatis现在可以使用的parameterType有基本数据类型和JAVA复杂数据类型
- 基本数据类型:包含int,String,Date等。基本数据类型作为传参,只能传入一个。通过#{参数名} 即可获取传入的值
- 复杂数据类型:包含JAVA实体类、Map。通过#{属性名}或#{map的KeyName}即可获取传入的值
1·基本数据类型:
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > select <include refid="Base_Column_List" /> from charge_way_tbl where id = #{id,jdbcType=INTEGER} </select>
与之对应的接口为:
ChargeWay selectByPrimaryKey(Integer id);
2·复杂的数据类型:
分页信息:
<select id="search" resultType="map" parameterType="com.jewery.bean.ChargewayBean" > select <include refid="Base_Column_List" /> from charge_way_tbl where 1 = 1 <if test="stylename != ''"> and stylename like '%${stylename}%' </if> limit #{start,jdbcType=INTEGER},#{rows,jdbcType=INTEGER} </select>
与之对应的接口为:
List search(ChargewayBean chargewayBean);
3· 另外mybatis还有另外一种形式,使用注解来注入多个参数的方式,这种方式需要在接口中使用@param
<select id="getCountByParams" resultType="java.lang.Integer"> select count(*) from charge_way_tbl where 1 = 1 <if test="stylename != ''"> and stylename like '%${stylename}%' </if> </select>
此时与之对应的接口为:
int getCountByParams(@Param("stylename") String stylename);