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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM