paramenterType:该参数只表示一个参数类型,按照类型进行匹配
@Param:按照名字进行匹配
一个参数:
@Param("id") String id
多个参数:
@Param("id") String id, @Param("name") String username
//List<User> searchMeaItemsVo(@Param("id") String id, @Param("name")String username);
Map类型:
paramenterType:使用的是map的key
@Param:是使用名字
void mapsave(@Param("map") Map<String,? extends Object> map);
<insert id="mapsave" parameterType="map">
insert into pac(productlevel,satelliteid) values (#{map.key1},#{map.key2})
</insert>
List类型:
parameterType:按类型识别
@Param:按名字匹配
List<Pac> selectBylist(@Param("param") List<String> list);
<select id="selectBylist" resultType="com.example.xmlsax_reader.entity.Pac">
select * from pac where productlevel in
<foreach collection="param" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</select>
注:该参数只表示一个参数类型,但是如果有多个参数的话,就不要使用该参数了。一个参数的这种其实没有必要写parameterType,而且还有就是多个参数的时候也没有必要写parameterType,也就是说,其实该参数的存在是不是特别必要的。其中@Param和parameterType 二者存其一即可。看名字就能知道ParameterType是按照类型进行匹配,而@Param是按照名字进行匹配。
在SQL语句中使用时,直接使用@Param(“name”)中的name,就是 #{@Param中的参数名称} 如#{name}
例:
在实际写的时候,可不用paramenterType,直接使用@Param:
List<MeaItemsVo> searchMeaItemsVo(@Param("modelCode") String modelCode, @Param("sparePartNo")String sparePartNo);
<select id="searchMeaItemsVo" resultType="czc.superzig.modular.system.operatingtable.entity.MeaItemsVo">
SELECT mi.*,pm.model_code
FROM mea_items AS mi
LEFT JOIN
part_model AS pm
ON mi.part_model_id = pm.id where 1=1
<if test="modelCode != null">
and pm.model_code LIKE "%"#{modelCode}"%"
</if>
<if test="sparePartNo != null">
and mi.spare_part_no LIKE "%"#{sparePartNo}"%"
</if>
</select>