springboot入門:mybatis多條件查詢

多條件查詢,例如用戶對象有多個字段,要通過uid, bid兩個條件查詢,如果兩個條件匹配就返回該結果。

自定義mapper

    <!--  通過uid和bid查詢是否存在記錄 (多條件查詢) -->
    <select id="selectByUidAndBid" parameterType="map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from b_collect
        where uid = #{uId,jdbcType=INTEGER} and bid = #{bId,jdbcType=INTEGER}
    </select>

注意,paramterType="map"  表示傳入的是Map

在Mapper文件中增加一行,傳參HashMap


    BlogCollect selectByUidAndBid(Map<String, Integer> userMap);

在serviceImpl中修改,傳入map 

 @Override
    public BlogCollectBean selectByUidAndBid(int uid, int bid) {
        Map<String,Integer> map = new HashMap<>();
        map.put("uId",uid);
        map.put("bId",bid);
        BlogCollect blog = blogCollectMapper.selectByUidAndBid(map);
        return mapper.map(blog, BlogCollectBean.class);
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章