问题描述
我使用mybatis和xml文件语法,实现了动态参数查询,如下所示。
但是现在切换到mybatis-plus后不知道怎么实现这种动态查询,目前的实现方法是这样。但是感觉很不好,不如if灵活方便,参数多了后很多if代码,难看。
图中的代码如下:
@Override
public Response getVideoCourse(Integer id){
//动态设置查询条件
HashMap<String, Object> map = new HashMap<>();
System.out.println("dddddddddddddddddd"+id);
if(id != null){
map.put("id",id);
}
// 如果有多个参数,就弄多个if,感觉不太好啊,很乱
// if(other !=null){
// map.put("other",other);
// }
List<VideoCourse> secondCategoryList = videoCourseMapper.selectByMap(map);
Response data = new Response();
data.setData(secondCategoryList);
data.setMsg("成功");
return data;
};
}
期望结果:
mybatis-plus如何实现类似xml的if标签,动态根据参数自动补充到where条件里呢?感谢大佬指导。
https://mp.baomidou.com/guide...