分页查询的模板 用mybatisplus做的 下面是处理字符串和数组之间转化

tech2024-07-31  51

public HashMap<Object, Object> queryAllAd(Integer page, Integer limit, String sort, String order, String name, String content){ HashMap<Object, Object> map = new HashMap<>(); QueryWrapper wrapper = new QueryWrapper<>(); if(order == “desc”){ wrapper.orderByDesc(sort); }else { wrapper.orderByAsc(sort); } // 关键字模糊查询 if(name != null && !name.isEmpty()){ wrapper.like(“name”,name); } if(content != null && !content.isEmpty()){ wrapper.like(“content”,content); } // 分页 IPage adPage = new Page<>(page, limit); // 查询 IPage adModelIPage = adMapper.selectPage(adPage, wrapper); long total=adMapper.selectCount(wrapper); map.put(“items”,adModelIPage.getRecords()); map.put(“total”,total); return map; }

@Override public HashMap<Object, Object> getListGoods(Integer page, Integer limit, String sort, String order) { //封装为一个map HashMap<Object, Object> map = new HashMap<>();

QueryWrapper<GoodsModel> wrapper = new QueryWrapper<>(); wrapper.ne("deleted",1); //根据创建时间降序显示 if(order.equals("desc")){ wrapper.orderByDesc(sort); }else{ wrapper.orderByAsc(sort); } //分页 Page<GoodsModel> listGoodsPage = new Page<>(page,limit); //查询 Page<GoodsModel> goodsModelPage = goodsMapper.selectPage(listGoodsPage, wrapper); //获取记录总数 long total = listGoodsPage.getTotal(); List<GoodsModel> records = goodsModelPage.getRecords(); //封装到新的GoodsVo中 因为gallery字段不同 List<Object> goodsVos = new ArrayList<>(); for (GoodsModel record : records) { GoodsVo goodsVo = new GoodsVo(); goodsVo.setId(record.getId()); goodsVo.setGoodsSn(record.getGoodsSn()); goodsVo.setName(record.getName()); goodsVo.setCategoryId(record.getCategoryId()); goodsVo.setBrandId(record.getBrandId()); String[] strings = new String[record.getGallery().length()]; String[] split = record.getGallery().replace("[", "").replace("]", "").replace("\"",""). split(","); for (int i = 0; i < split.length; i++) { if(goodsVo.getGallery()==null){ goodsVo.setGallery(new ArrayList<>()); goodsVo.getGallery().add(split[i]); }else{ goodsVo.getGallery().add(split[i]); } } goodsVo.setKeywords(record.getKeywords()); goodsVo.setBrief(record.getBrief()); goodsVo.setIsOnSale(record.getIsOnSale()); goodsVo.setSortOrder(record.getSortOrder()); goodsVo.setPicUrl(record.getPicUrl()); goodsVo.setShareUrl(record.getShareUrl()); goodsVo.setIsNew(record.getIsNew()); goodsVo.setIsHot(record.getIsHot()); goodsVo.setUnit(record.getUnit()); goodsVo.setCounterPrice(record.getCounterPrice()); goodsVo.setRetailPrice(record.getRetailPrice()); goodsVo.setDetail(record.getDetail()); goodsVo.setAddTime(record.getAddTime()); goodsVo.setUpdateTime(record.getUpdateTime()); goodsVo.setDeleted(record.getDeleted()); goodsVos.add(goodsVo); map.put("total",total); map.put("items",goodsVos); } return map; }

自信看 不一样 多了双引号

最新回复(0)