传递多个参数有三种方式
第一种使用@param注解方式
第二种使用map传递参数
第三种封装对象
dao接口代码如下:
public interface BookMapper {
// 使用@param注解传递参数
List<Book> selectBookByName(@Param("name") String name, @Param("number") int number);
// 使用map传递参数
List<Book> selectBookByMap(Map<String,Object> param);
}
xml配置
<resultMap id="baseResult" type="com.zh.dao.Book">
<id column="book_id" property="bookId"/>
<result column="name" property="name"/>
<result column="number" property="number"/>
</resultMap>
<select id="selectBookByName" resultType="com.zh.dao.Book">
select * from book where name=#{name} and number=#{number}
</select>
<select id="selectBookByMap" resultMap="baseResult" parameterType="java.util.Map">
select * from book where name=#{name} and number=#{number}
</select>