use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project demo-SpringBoot by Max-Qiu.
the class TestGroupByAndHaving method testGroup.
/**
* 分组
*/
@Test
public void testGroup() {
// SELECT classes_id, count(*) FROM smp_student GROUP BY classes_id
QueryWrapper<Student> wrapper = new QueryWrapper<>();
wrapper.select("classes_id, count(*)").groupBy("classes_id");
List<Map<String, Object>> maplist = studentMapper.selectMaps(wrapper);
for (Map<String, Object> mp : maplist) {
System.out.println(mp);
}
// lambda语法可能不太方便获取count(*)这种
// lambdaQueryWrapper groupBy
LambdaQueryWrapper<Student> lambdaQueryWrapper = new QueryWrapper<Student>().lambda().select(Student::getClassesId).groupBy(Student::getClassesId);
for (Student user : studentMapper.selectList(lambdaQueryWrapper)) {
System.out.println(user);
}
}
use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project demo-SpringBoot by Max-Qiu.
the class TestOther method testOperationAllTable.
/**
* 防止操作全表
*
* 插件内添加 interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
*
* 可在遇到全表操作时,抛出异常
*/
@Test
void testOperationAllTable() {
userMapper.selectList(new QueryWrapper<>());
userMapper.deleteById(1L);
userMapper.insert(new User().setAge(18).setEmail("13"));
User user = new User();
user.setUsername("test_update");
userMapper.update(user, new QueryWrapper<User>().eq("id", 1L));
try {
userMapper.update(new User().setAge(18), new QueryWrapper<>());
} catch (MyBatisSystemException e) {
System.out.println("发现全表更新");
}
try {
userMapper.delete(new QueryWrapper<>());
} catch (MyBatisSystemException e) {
System.out.println("发现全表删除");
}
List<User> list = userMapper.selectList(new QueryWrapper<>());
if (list.size() == 0) {
System.out.println("数据都被删掉了");
} else {
System.out.println("数据还在");
}
}
use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project waynboot-mall by wayn111.
the class ChannelServiceImpl method checkChannelNameUnique.
@Override
public String checkChannelNameUnique(Channel channel) {
long channelId = Objects.isNull(channel.getId()) ? -1L : channel.getId();
Channel shopChannel = getOne(new QueryWrapper<Channel>().eq("name", channel.getName()));
if (shopChannel != null && shopChannel.getId() != channelId) {
return SysConstants.NOT_UNIQUE;
}
return SysConstants.UNIQUE;
}
use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project waynboot-mall by wayn111.
the class ChannelServiceImpl method checkChannelCodeUnique.
@Override
public String checkChannelCodeUnique(Channel channel) {
long channelId = Objects.isNull(channel.getId()) ? -1L : channel.getId();
Channel shopChannel = getOne(new QueryWrapper<Channel>().eq("code", channel.getCode()));
if (shopChannel != null && shopChannel.getId() != channelId) {
return SysConstants.NOT_UNIQUE;
}
return SysConstants.UNIQUE;
}
use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project waynboot-mall by wayn111.
the class DictServiceImpl method deleteDictTypeById.
@Transactional
@Override
public boolean deleteDictTypeById(List<Long> dictIds) {
for (Long dictId : dictIds) {
Dict dict = getById(dictId);
remove(new QueryWrapper<Dict>().eq("parent_type", dict.getValue()));
}
return removeByIds(dictIds);
}
Aggregations