mybatis中mapper传多个入参

有三种方式

1、使用占位符#{0},#{1}....对应顺序就是参数的顺序

#方法签名
List<TbItem> selectByPage(int page, int rows);

#sql语句
<select id="selectByPage" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List" />
    from tb_item LIMIT #{0} , #{1}
  </select>

2、使用map封装入参

#生成map入参
public List<TbItem> getItemByPage(int page , int rows){
        Map paramMap = new HashMap();
        paramMap.put("page",page);
        paramMap.put("rows" , rows);
        List<TbItem> tbItems = tbItemMapper.selectByPage(paramMap);
        return tbItems;
    }

#sql
<select id="selectByPage" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List" />
    from tb_item LIMIT #{page} , #{rows}
  </select>

3、使用@Param

#mapper中接口的签名
List<TbItem> selectByPage(@Param("page") int page , @Param("rows") int rows);

#sql
<select id="selectByPage" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List" />
    from tb_item LIMIT #{page} , #{rows}
  </select>
原文地址:https://www.cnblogs.com/tianphone/p/10945152.html