进阶之路002 增删改查/数据导入导出之查询功能
Posted pureray-hui
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了进阶之路002 增删改查/数据导入导出之查询功能相关的知识,希望对你有一定的参考价值。
//Controller
@ResponseBody
@RequestMapping("/lightSplitBox")
@RequiresPermissions("zkgj:detail:list")
public R lightSplitBox(@RequestParam Map<String, Object> params){
PageUtils page = detailService.lightSplitBox(params);
String s=(String) params.get("params001");
return R.ok().put("page", page);
}
//Service接口
PageUtils lightSplitBox(Map<String, Object> params);//查询所有的分光想
//接口实现类
@Override
public PageUtils lightSplitBox(Map<String, Object> params) {
long page=Long.parseLong((String) params.get("page"));
long limit=Long.parseLong((String) params.get("limit"));
String order=(String) params.get("order");//获取排序方式
String sidx=(String) params.get("sidx");//获取排序的字段
DetailEntity detailEntity=new DetailEntity();
String opticalBoxName=(String)params.get("opticalBoxName");//获取查询参数
String opticalBoxType=(String)params.get("opticalBoxType");//获取查询参数
Page<DetailEntity> pagination = new Page<>(page,limit); //分页
List<DetailEntity> list = detailDao.lightSplitBox(pagination,order,sidx,opticalBoxType,opticalBoxName);
pagination.setRecords(list);
return new PageUtils(pagination);
}
//Dao层
List<DetailEntity> lightSplitBox(@Param("page") Page<DetailEntity> page,@Param("order") String order,@Param("sidx") String sidx,@Param("opticalBoxType") String opticalBoxType,@Param("opticalBoxName") String opticalBoxName);
//sql
<select id="getDetail" resultType="io.renren.modules.zkgj.entity.DetailEntity">
select
DATE_FORMAT(a.check_date,‘%Y-%m-%d‘) AS checkDateString,
a.id,
a.operator,
a.user_info,
a.check_date as checkDate,
COUNT(`operator`) AS sumPort
FROM tb_detail a
<where>
<if test="operator !=null and operator != ‘‘ ">
and a.operator like ‘%${operator}%‘
</if>
<if test="checkDateString !=null and checkDateString != ‘‘ ">
and DATE_FORMAT(a.check_date,‘%Y-%m-%d‘)=#{checkDateString}
</if>
<if test="params.sql_filter!=null">
and ${params.sql_filter}
</if>
</where>
GROUP BY DATE_FORMAT(a.check_date,‘%Y-%m-%d‘),a.operator
<choose>
<when test="sidx !=‘‘ and sidx != null">
ORDER BY a.${sidx} ${order}
</when>
<otherwise>
ORDER BY a.check_date desc
</otherwise>
</choose>
</select>
以上是关于进阶之路002 增删改查/数据导入导出之查询功能的主要内容,如果未能解决你的问题,请参考以下文章