无感五 2019-03-26 18:44 采纳率: 50%
浏览 1237
已采纳

这段代码我是直接写在Controller上面得,但是我想改为写在Service上请问应该怎么改呢

 //查询
    @ApiOperation(value="船东发布展示信息列表", notes="船东发布展示信息列表的接口")
    @RequestMapping(value = "/findContent" , method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name="startDate", value="开始时间", required=false),
            @ApiImplicitParam(name="endDate", value="结束时间", required=false),
            @ApiImplicitParam(name="startLoading", value="最小吨数", required=false),
            @ApiImplicitParam(name="endLoading", value="最大吨数", required=false),
            @ApiImplicitParam(name="typeShip", value="船舶类型", required=false),
            @ApiImplicitParam(name="emptyPort", value="港口", required=false)
    })
    public SysResult find(Date startDate,Date endDate , String startLoading , String endLoading,
                             Long typeShip , Long emptyPort){
        try{
            EntityWrapper<ShipRelease> wrapper = new EntityWrapper<>();
            //只能状态为发布中的数据展示出来
            wrapper.where( "state = {0}  ", 4 );
            //筛选时间日期
            if(startDate != null && endDate != null) {
                wrapper.where( "empty_date >= {0}  ", startDate );
                wrapper.and( " empty_date <= {0}", endDate );
            }
            //筛选两数值之剑
            if(startLoading != null && endLoading != null) {
            wrapper.where( "tonnage_loading >= {0}  ", startLoading );
            wrapper.and( " tonnage_loading <= {0}", endLoading );
            }
            //筛选类型1
            if(typeShip != null) wrapper.where("type_ship={0}", typeShip);
            //筛选类型2
            if(emptyPort != null) wrapper.where("empty_port={0}", emptyPort);
            wrapper.setSqlSelect("id, title,empty_date,aircraft_sky,tonnage_loading,type_ship");
            List<ShipRelease> shipReleaseList =  webShipownerReleaseShowMapper.selectList( wrapper );
            return SysResult.ok(shipReleaseList);
        }catch (Exception e){
            e.printStackTrace();
            return SysResult.build(201,"查询失败");
        }
    }

使用得是spring-boot+mybatisPlus

  • 写回答

4条回答 默认 最新

  • 无感五 2019-04-29 05:21
    关注

    方法重写之后,之后解决了这个问题

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗