mybatis实现多条件查询

代码中实现:

 /**
     * 根据各条件查询列表
     *
     * @return
     */
    @RequestMapping(value = "/pageListByCondition")
    public String pageListByCondition(@RequestBody Map map) {
        Integer pageNo =Integer.parseInt(map.get("pageNo").toString());
        Integer pageSize =Integer.parseInt(map.get("pageSize").toString());
        if(map.get("uiId")== null){
            map.put("uiId",sessionService.getCurrentUiId());
        }else {
            Integer uiId = Integer.parseInt(map.get("uiId").toString());
        }
        Integer iiId = map.get("iiId")== null?null:Integer.parseInt(map.get("iiId").toString());
         Integer oiType= map.get("iiId")== null?null:Integer.parseInt(map.get("oiType").toString());
        Integer oiStatus = map.get("oiStatus")== null?null:Integer.parseInt(map.get("oiStatus").toString());
        if(pageNo==null||pageSize==null){
            return ApiResultHelper.Failure(Constants.API_RESULT_PARAM_NOTNULL);
        }else {
            PageInfo pageInfo = orderInfoService.pageListByCondition(map);
            return ApiResultHelper.Success(pageInfo);
        }
    }

这样把所需要的参数通过map传入就可以了
mapper.xml中实现:

<select id="pageListByCondition" resultMap="BaseResultMap" parameterType="java.util.Map">
        select
        <include refid="Base_Column_List"/>
        from order_info
        <where>

            <if test="oiStatus != null">
                and oi_status = #{oiStatus,jdbcType=INTEGER}
            </if>
            <if test="iiId != null">
                and ii_id = #{iiId,jdbcType=INTEGER}
            </if>
            <if test="uiId != null">
                and ui_id = #{uiId,jdbcType=INTEGER}
            </if>
            <if test="oiType != null">
                and oi_type = #{oiType,jdbcType=INTEGER}
            </if>
            <if test="oiEmergency != null">
                and oi_emergency = #{oiEmergency,jdbcType=INTEGER}
            </if>
        </where>
    </select>
发布了26 篇原创文章 · 获赞 3 · 访问量 1万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览