//查询
@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
方法重写之后,之后解决了这个问题
将find方法的代码整体搬迁到Service中,然后在Controller中,调用这个Service的find就行了
public SysResult find(Date startDate,Date endDate , String startLoading , String endLoading,
Long typeShip , Long emptyPort){
try{
EntityWrapper 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 shipReleaseList = webShipownerReleaseShowMapper.selectList( wrapper );
return SysResult.ok(shipReleaseList);
}catch (Exception e){
e.printStackTrace();
return SysResult.build(201,"查询失败");
}
把这个代码放在service里
把wrapper对应的包也放进去
如果挪动到Service中定义,那么find方法的每个参数都应该进行判空处理。
其次,这个webShipownerReleaseShowMapper变量是在哪里定义的,有没有可能是空指针?
最后,空指针应该是很容易定位的,看到异常的那行的代码是对那个对象进行的.操作。