我是靠谱客的博主 甜美保温杯,最近开发中收集的这篇文章主要介绍querywrapper多条件查询,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

concroller:

/**
* 查询列表
* @return
*/
@ApiResponses({@ApiResponse(code = 200, message = "正常", response = SourceMateria.class)})
@ApiOperation(value="全部查询")
@GetMapping
public AjaxResult selectAll(@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
@ApiParam(name="id", value="素材id(根据id查询)")@RequestParam(value = "id", required=false)Long id,
@ApiParam(name="screenId", value="筛选条件号:1001=最新,1002=最热,1003=免费,1004=付费")@RequestParam(value = "screenId", required=false)Integer screenId,
@ApiParam(name="typeId", value="素材类型id(根据类型查询)")@RequestParam(value = "typeId", required=false)Long typeId,
@ApiParam(name="title", value="素材标题(根据标题模糊查询)")@RequestParam(value = "title", required=false)String title) {
Page<SourceMateria> page = new Page<SourceMateria>(pageNo, pageSize);
QueryWrapper<SourceMateria> queryWrapper=new QueryWrapper<>();
if(id!=null&&id>0){
queryWrapper=queryWrapper.eq("t_source_materia.id",id);
//添加访问量
SourceMateria sourceMateria = sourceMateriaService.selectById(id);
sourceMateria.setTraffic(sourceMateria.getTraffic()+1);
sourceMateriaService.updateById(sourceMateria);
}
if(typeId!=null&&typeId>0){
queryWrapper=queryWrapper.eq("t_source_materia_type.id",typeId);
}
if(title!=null&&title!=""){
queryWrapper=queryWrapper.like("t_source_materia.title",title);
}
if(screenId!=null&&screenId>0){
switch (screenId){
case 1001: queryWrapper=queryWrapper.orderByDesc("create_time");
break;
case 1002: queryWrapper=queryWrapper.orderByDesc("share_number");
break;
case 1003: queryWrapper=queryWrapper.eq("smart_coin",0);
break;
case 1004: queryWrapper=queryWrapper.gt("smart_coin",0);
break;
default:
break;
}
}
IPage<SourceMateria> pageInfo = sourceMateriaService.restListPage(queryWrapper,page);
List<SourceMateriaType> sourceMateriaTypes = sourceMateriaTypeService.selectList(null);
Map<String, Object> map = new HashMap<>();
map.put("pageInfo",new PageInfo(pageInfo));
map.put("allType",sourceMateriaTypes);
return AjaxResult.success(map);
}

IService :

/**
* 接口查询分页列表
* @param queryWrapper
* @param page
* @return
*/
IPage<SourceMateria> restListPage(QueryWrapper<SourceMateria> queryWrapper, IPage page);

ServiceImpl :

/**
* 接口查询分页列表
* @param queryWrapper
* @param page
* @return
*/
@Override
public IPage<SourceMateria> restListPage(QueryWrapper<SourceMateria> queryWrapper, IPage page) {
return page.setRecords(sourceMateriaMapper.restListPage(queryWrapper,page));
}

Mapper :

List<SourceMateria> restListPage(@Param(Constants.WRAPPER) QueryWrapper<SourceMateria> queryWrapper, IPage<SourceMateria> page);

XML :

<select id="restListPage" resultType="com.mbyte.easy.admin.entity.SourceMateria">
SELECT
t_source_materia.id,
t_source_materia.source_id,
t_source_materia_type.name as name,
t_source_materia.Icon,
t_source_materia.title,
t_source_materia.content,
t_source_materia.video_url,
t_source_materia.smart_coin,
t_source_materia.traffic,
t_source_materia.share_number,
t_source_materia.is_goods,
t_source_materia.create_time,
t_source_materia.update_time
FROM
t_source_materia
INNER JOIN t_source_materia_type ON t_source_materia.source_id = t_source_materia_type.id
${ew.customSqlSegment} //querywrapper导入
</select>

最后

以上就是甜美保温杯为你收集整理的querywrapper多条件查询的全部内容,希望文章能够帮你解决querywrapper多条件查询所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部