@RequestMapping(value = "/qryServiceMonitoring/{pageNum}/{pageSize}",produces = "application/json") public JsObj qryServiceMonitoring(@PathVariable Long pageNum,@PathVariable Long pageSize,String jsonStr,String token) { JsObj jsObj = new JsObj(JsObj.CODE_SUCCESS); try { List<ServiceMonitoring> list = service.list(); for (ServiceMonitoring serviceMonitoring : list) { String smAddress = serviceMonitoring.getSmAddress(); JsObj httpPost = HttpUtil.httpPost(smAddress, jsonStr, token); String resCode = httpPost.getResCode(); //可以调通0 不能调通-1 if (resCode.equals("0")){ serviceMonitoring.setSmParameter("在线"); }else { serviceMonitoring.setSmParameter("离线"); } } jsObj.setResObj(list); } catch (Exception e) { jsObj.setCodeMsg(JsObj.CODE_EXCEPETION, "查询服务监控表错误" + e.getLocalizedMessage()); log.error("查询服务监控表错误", e); } return jsObj; } 根据这段方法写个分页查询
时间: 2024-02-14 15:27:13 浏览: 96
根据你提供的代码,我会基于MyBatis-Plus进行相应的分页查询的修改。请注意,这里假设你已经正确配置了MyBatis-Plus和相关的Mapper接口。
```java
@RequestMapping(value = "/qryServiceMonitoring", produces = "application/json")
public JsObj qryServiceMonitoring(@RequestParam(defaultValue = "1") Long pageNum,
@RequestParam(defaultValue = "10") Long pageSize,
String jsonStr, String token) {
JsObj jsObj = new JsObj(JsObj.CODE_SUCCESS);
try {
// 创建分页对象
Page<ServiceMonitoring> page = new Page<>(pageNum, pageSize);
// 执行分页查询
IPage<ServiceMonitoring> serviceMonitoringPage = service.page(page);
// 获取分页结果
List<ServiceMonitoring> list = serviceMonitoringPage.getRecords();
// 根据需要进行处理
for (ServiceMonitoring serviceMonitoring : list) {
String smAddress = serviceMonitoring.getSmAddress();
JsObj httpPost = HttpUtil.httpPost(smAddress, jsonStr, token);
String resCode = httpPost.getResCode();
if (resCode.equals("0")) {
serviceMonitoring.setSmParameter("在线");
} else {
serviceMonitoring.setSmParameter("离线");
}
}
// 设置结果对象
jsObj.setResObj(list);
} catch (Exception e) {
jsObj.setCodeMsg(JsObj.CODE_EXCEPETION, "查询服务监控表错误" + e.getLocalizedMessage());
log.error("查询服务监控表错误", e);
}
return jsObj;
}
```
在这个修改后的方法中,我们使用`@RequestParam`注解来接收页码和每页显示的记录数,默认为1和10。然后,我们创建了一个`Page`对象,并将其传递给`service.page()`方法进行分页查询。最后,根据需要进行处理并设置结果对象。
请确保已经正确引入MyBatis-Plus的依赖并配置了相应的Mapper接口。
阅读全文