Example example = new Example(CandidateBrandEntity.class);
example
//.selectProperties("cabId","cabName")
.and().andEqualTo("cabDeleted",0)
.andLike("cabName","%d%");
// 排序
example.orderBy("cabCreatedTime")
/*.desc()*/
.orderBy("cabId").desc();
// 获得结果
List<CandidateBrandEntity> brands = brandEntityMapper.selectByExample(example);
方式二:Criteria方式(可使用criteria完成动态sql拼接)
Example example = new Example(MybatisDemo.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo(“count”, 0)
.andLike(“name”, “%d%”);
example.orderBy(“count”)
//.desc()
.orderBy(“name”).desc();
List demos = mybatisDemoMapper.selectByExample(example);
方式三:Example.builder 方式(其中where从句中内容可以拿出来进行动态sql拼接)
Example example = Example.builder(MybatisDemo.class)
.select(“cabId”,“cabName”)
.where(Sqls.custom().andEqualTo(“count”, 0)
.andLike(“name”, “%d%”))
.orderByDesc(“count”,“name”)
.build();
List demos = mybatisDemoMapper.selectByExample(example);
方式四:Example.builder + Weekend方式,优势:不用输入属性名,避免数据库有变动或输入错误就会出错
//获得seekendsql
WeekendSqls sqls = WeekendSqls.custom();
//可进行动态sql拼接
sqls = sqls.andEqualTo(MybatisDemo::getCount,0).andLike(MybatisDemo::getName,"%d%");
//获得结果
List demos = mybatisDemoMapper.selectByExample(Example.builder(MybatisDemo.class).where(sqls).orderByDesc(“count”,“name”).build());