分页
public AjaxResult getBlindBoxInfo(@RequestParam(name=“pageNo”, defaultValue=“1”) Integer pageNo,
@RequestParam(name=“pageSize”, defaultValue=“10”) Integer pageSize) {
String userId = AuthUtil.getAppUserId();
if(StringUtils.isEmpty(userId)){
return AjaxResult.error(HttpStatus.UNAUTHORIZED,“未登录”);
}
IPage page = new Page<>(pageNo,pageSize);
List<BlindBoxVO> info = blindBoxService.selectBlindBoxInfo(page,userId);page.setRecords(info);return AjaxResult.success(page);
}
应用封装方法
增加
save 方法直接实体类带入,增加失败会报错
public AjaxResult createBlindBox(@RequestBody BlindBox blindBox) {
Long userId = AuthUtil.getAppLoginUser().getId();
if(userId == null){
return AjaxResult.error(HttpStatus.UNAUTHORIZED,“未登录”);
}
blindBox.setAppuserId(userId);
blindBox.setCreateTime(new Date());
blindBox.setUpdateTime(new Date());
blindBox.setCreateBy(String.valueOf(userId));
blindBox.setUpdateBy(String.valueOf(userId));
boolean result = blindBoxService.save(blindBox);
if(!result){
return AjaxResult.error(“添加失败,请重新操作”);
}
return AjaxResult.success();
}
saveOrUpdate 方法先保存再更新,传入实体类
DynamicBlockRecord record = new DynamicBlockRecord();
record.setAppuserId(userId);
record.setCreateTime(new Date());
record.setDynamicId(dynamicInfo.get(0).getId());
dynamicBlockRecordService.saveOrUpdate(record);
修改
1.update方法 根据set修改值,eq为where条件
UpdateWrapper updateWrapper = new UpdateWrapper<>();
updateWrapper.set(“del_flag”,1).set(“update_time”,new Date())
.set(“update_by”,String.valueOf(userId))
.eq(“id”,blindBox.getId());
boolean result = blindBoxService.update(null,updateWrapper);
2.update
appuserService.update(new UpdateWrapper().eq(“id”,userId).set(“status”,2));
3.updateById 根据实体类进行修改,实体类中有id
查询
1.getById根据id查询
Appuser operationUser = appuserService.getById(userId);
2.getOne 查询唯一值
Appuser userInfo = appuserService.getOne(new QueryWrapper().eq(“id”,id).eq(“del_flag”,0));
3.selectById(Serializable id); // 根据 主键 ID 查询数据
Appuser operationUser =appuserMapper.selectById(new QueryWrapper().eq(“del_flag”, 0).eq(“id”, userId));
4.list
appuserService.list(new QueryWrapper().in(“identity”,“2,3”)
.eq(“is_topic”,1).eq(“del_flag”,0).orderByAsc(“topic_no”).last(“limit 0,3”));
appTopicService.list(new QueryWrapper()
.eq(“del_flag”,0).orderByAsc(“sort”).last(“limit 0,3”));
删除
remove 删除
QueryWrapper queryWrapper= new QueryWrapper<>();
queryWrapper.eq(“care_uesr”,appUserCare.getCareUesr()).eq(“appuser_id”,userId);
result = appUserCareService.remove(queryWrapper);
removeById根据id进行删除
boolean result = appUserFunService.removeById(id);
统计数量
1.count方法
appUserCareService.count(new QueryWrapper().eq(“appuser_id”,userId));
2.getMap方法 有日期类的比较,传入开始结束时间为String
QueryWrapper queryWrapper = new QueryWrapper().eq(“appuser_id”, userId)
.eq(“type”, 2).ne(“balance_type”, 5)
.apply(“UNIX_TIMESTAMP(create_time) >= UNIX_TIMESTAMP('” + startDate + “')”)
.apply(“UNIX_TIMESTAMP(create_time) <= UNIX_TIMESTAMP('” + endTime + “')”)
.select("IFNULL(sum(amount),0) as total ");
balanceRecordService.getMap(queryWrapper).get(“total”);