在网上查了下,其他人的说法是暂时找不到example对a and ( b or c)的直接sql语句构造方法,都是把a and ( b or c)转成( a and b) or ( a and c) ,其实example是支持除了这样处理的,以下两种写法可以实现a and ( b or c)的sql语句,个人更支持使用第一种,
pom.xml依赖
<dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper</artifactId> <version>4.0.4</version> </dependency>
1、使用Example.and()和Example.Criteria.orLike(String property, String value)
Example example =new Example(PathInfo.class); Example.Criteria criteria =example.createCriteria(); //模糊查询内容 if(StringUtils.isNotBlank(params.getFuzzySearch())){ Example.Criteria criteria2 =example.and(); criteria2.orLike("pathCode",SqlUtil.like(params.getFuzzySearch())); criteria2.orLike("pathName",SqlUtil.like(params.getFuzzySearch())); }
//路径类型:1菜单,2页面,3按钮 if(null!=params.getPathType()){ criteria.an