The conditions to achieve multi-screening based on Spring Boot

Buttons need to be screened to select multiple conditions, the argument to the back-end, and the results get screened.

Backend interface for data processing

@PostMapping(value = "/getResult")
public HttpResult getResult(HttpServletRequest request){
    //数据类型
    HttpResult result = new HttpResult();
    Map<String,String[]> paramMap = request.getParameterMap();
    //当传入的参数为空时确保也能够执行
    if(paramMap.size()>=0){
        Map<String,String> condtionMap = new HashMap();
        for(String key: paramMap.keySet()){
            condtionMap.put(key,paramMap.get(key)[0]);
        }
        try{
            List<JobDO> sjob =service.selectJob(condtionMap);
            return HttpResult.build(sjob);
        }catch (Exception e){
            result = HttpResult.build(false,"获取结果失败");
            return result;
        }
    }else{
        result = HttpResult.build(false,"查询结果失败");
        return result;
    }
}

DAO layer data filtering, dynamic sql

Interger types of parameters for the query result 0:00 exception, Mapper layer sql statement when the condition query status as Interger type, when the status is 0, the query results for all cases, because status is Interger type, it is 0, the default It is null.

Solution: a judge to pay more

"<if test=\"status==0 ? '0':status \"> and status= #{status} </if>"

@Results(id = "job",value = {
        @Result(column = "id", property = "id"),
        @Result(column = "name", property = "name"),
        @Result(column = "state", property = "state")
})

@ResultMap(value = "job")
@Select("<script>" +
        "select * from table" +
        "<where>" +
        "<if test=\"conditionMap.id !=null  and conditionMap.id!=''\"> id=#{conditionMap.id}</if>" +
        //字段的类型为封装类型 值为0时,会转为空
        "<if test=\"conditionMap.state == 0\">and state=0 </if> "+
        "<if test=\"conditionMap.state !=null and conditionMap.state!=''\">and state=#{conditionMap.state}</if>" +
        "</where>" +
        "</script>"
)
List<JobDO> selectJob(@Param("conditionMap") Map<String,String> conditionMap);

 react front-end request call interface

//筛选按钮
    doFilter = ()=>{
        //配置路径,微服务名称 ,接口参数
        request.post(`/api/jobservice/job/getResult`)
            .set('Content-Type', 'application/x-www-form-urlencoded')
            .send({
                //参数是否传入
                id:this.state.Id ? this.state.Id :undefined,
                //状态为开启,关闭,全部,全部情况下为undefined
                states : (this.state.choseState && this.state.choseState != 2  ? this.state.choseState : undefined)
            })
            .end((err,res)=>{
                if(!err){
                    let response=JSON.parse(res.xhr.response);
                    if(response.code='200'){
                        //对取得的值倒序
                        this.setState({list:response.data.reverse()})
                    }else{
                        message.error(response.msg);
                    }
                }else{
                    message.error("服务暂不可用");
                }
                this.setState({ afterFiltered: true });
            });
    }

 

 

Published 36 original articles · won praise 19 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_27182767/article/details/89647917