mybatis plus 写sql语句

一、api:

public Map<String,Object> selectManagerList(ManagerBean managerBean){
    Page page = new Page(managerBean.getPage()==null ? 1:managerBean.getPage(),managerBean.getPageSize()==null ? 10 :managerBean.getPageSize());
   try {
       return managerService.selectManagerList(page,managerBean);
   }catch (Exception e){
       DingTalkNotifyTest.sendAliErrorMessage(Thread.currentThread().getStackTrace()[1].getClassName()
               ,Thread.currentThread().getStackTrace()[1].getMethodName(),e.getMessage(),
               RocketMqConst.DINGDING_ERROR,"管理人员列表");
   }
   return null;
}

二、service:

public Map<String, Object> selectManagerList(Page page, ManagerBean managerBean) {
    Map<String, Object> map = new HashMap<>();
    QueryWrapper<Manager> queryWrapper = new QueryWrapper<>();
    if(StringUtils.isNotEmpty(managerBean.getManagerName())){
        queryWrapper.eq("manager_name",managerBean.getManagerName());
    }
    if(StringUtils.isNotEmpty(managerBean.getManagerMobile())){
        queryWrapper.eq("manager_mobile",managerBean.getManagerMobile());
    }
    queryWrapper.eq("del_flag","0");
   //获取所有管理人员
    List<ManagerBean> managerList  = managerMapper.selectManagerList(page,queryWrapper);
    managerList.stream().forEach(manager -> {
        manager.setManagerMobile(Desensitization.getStarString(manager.getManagerMobile(),1,1));
        //获取管理员服务的小区集合
     List<String> areas = communityMapper.selectNamesById(manager.getId());
      if(areas.size()<1){
          manager.setAreas("");
      }
      //将小区用逗号分隔
        manager.setAreas(areas.stream().collect(Collectors.joining(",")));
    });
    map.put("managerList",managerList);
    map.put("currentPage",managerBean.getPage()==null ? 1: managerBean.getPage());//当前页数
    map.put("totalCount",page.getTotal());//总记录数
    map.put("status",true);
    return map;
}

三、mapper或者dao:

@Select("select * from mysql_data ${ew.customSqlSegment}")
List<MysqlData> getAll(@Param(Constants.WRAPPER) Wrapper wrapper);

 

<select id="getAll" resultType="MysqlData">
    SELECT * FROM mysql_data ${ew.customSqlSegment}
</select>

上一篇:oracle导出数据字典


下一篇:mybatis-plus入门案例