首先要清楚查询条件在model中
方法1:先从model中取得查询条件的值,然后在将model的属性值都设null,这样mybatis-plus在分页查询的时候不会精确搜索。
方法2:或者在model中的属性上加@TableField(condition = SqlCondition.LIKE)
,condition = 等号后的内容可以自定义,自定义内容是sql条件,如@TableField(condition ="自定义")
SELECT xiaoqu_id AS xiaoquId,xiaoqu_code AS xiaoquCode,xiaoqu_name AS xiaoquName,remark,door_number AS doorNumber,build_total AS buildTotal,comm_hous_total AS commHousTotal,comm_resi_total AS commResiTotal,comm_area AS commArea,community_id AS communityId,is_delete AS isDelete,data_source_id AS dataSourceId,adm_district_id AS admDistrictId,adm_street_id AS admStreetId,comm_gis_id AS commGisId,src_update_time AS srcUpdateTime,fg_update_time AS fgUpdateTime,update_time AS updateTime FROM pb_xiaoqu WHERE xiaoqu_name LIKE CONCAT('%','福苑','%') AND (IS_DELETE = '0') LIMIT 0,5
不加@TableField(condition = SqlCondition.LIKE)
时查询sql如下
SELECT xiaoqu_id AS xiaoquId,xiaoqu_code AS xiaoquCode,xiaoqu_name AS xiaoquName,remark,door_number AS doorNumber,build_total AS buildTotal,comm_hous_total AS commHousTotal,comm_resi_total AS commResiTotal,comm_area AS commArea,community_id AS communityId,is_delete AS isDelete,data_source_id AS dataSourceId,adm_district_id AS admDistrictId,adm_street_id AS admStreetId,comm_gis_id AS commGisId,src_update_time AS srcUpdateTime,fg_update_time AS fgUpdateTime,update_time AS updateTime FROM pb_xiaoqu WHERE xiaoqu_name='福苑' AND (IS_DELETE = '0')
PbCommunityController
@TargetDataSource("ds3")
@RestController
@RequestMapping("/api/pbCommunity")
public class PbCommunityController extends /*SingleRecordControl<PbCommunity>*/
BaseController<PbCommunityService,
PbCommunityMapper, PbCommunity, Long> {
}
/**
* 通用接口
* 获取列表,可以分页。详情接口
*
* @param page 分页
* @param object 传入的查询条件
* @param service 对应的service,这个参数很重要!!
* @return
*/
public ResponseObj<Page<T>> listPage(Page page, Object object, ServiceImpl service) {
Class<?> clazz = object.getClass(); //获取obj的Class
String tableName = clazz.getSimpleName();
Page<T> pageList = null;
Object obj = null;
Map<String, Object> map = MapBeanUtil.beanToMap(object);
if (tableName.endsWith("WithBLOBs")) {
String[] withBLOBses = tableName.split("WithBLOBs");
tableName = withBLOBses[0].toString();
obj = MapBeanUtil.returnObj(tableName, map); //备份表结构
pageList = service.selectPage(page, new EntityWrapper<>(obj).eq("IS_DELETE", "0"));
} else {
pageList = service.selectPage(page, new EntityWrapper<>(object).eq("IS_DELETE", "0"));
}
return new ResponseObj<>(pageList, RetCode.SUCCESS);
}
网友评论