mybati的xml中sql 当传入多个类型不同的参数,目前知道有4种方法:
1. 把参数按照key-value的格式存入map,参数类型为map
2. 把参数封装成POJO,参数类型为实体类型
3. 可以按照占位符的方式;如下
<select id="selectOne" resultMap="ResultMap">
select * from user where user_name = #{0} and user_area=#{1}
</select>4. 如果参数类型不同,可以用@Param的方式
mapper接口:
Public User selectUser(@param(“userName”)Stringname,@param(“userArea”)String area);xml中: <select id=" selectUser" resultMap="BaseResultMap">
select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
</select>
本文介绍了在MyBatis中处理多个不同类型参数的四种方法:使用Map存储参数、封装为POJO、通过占位符指定参数位置及使用@Param注解明确指定参数名称。

2169

被折叠的 条评论
为什么被折叠?



