2024.4.11
优化了node的组合条件查询和分页
This commit is contained in:
@@ -36,4 +36,19 @@ public class NodeProvider {
|
||||
//返回sql语句
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String GetTotal(Map<String,Object> condition){
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.append("select count(1) from node where 1=1");
|
||||
|
||||
//开如拼接查询条件
|
||||
if (condition.containsKey("nodename")){
|
||||
sb.append(" and nodename like concat('%', #{nodename},'%')");
|
||||
}
|
||||
|
||||
//……如果有其他条件,就继续
|
||||
|
||||
//返回sql语句
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.hongliang.videotask.bean;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PageResultBean<T> {
|
||||
private int pageNum;
|
||||
private int pageSize;
|
||||
private int total;
|
||||
private List<T> list;
|
||||
}
|
||||
@@ -19,7 +19,6 @@ public class NodeControl {
|
||||
|
||||
@PostMapping("list")
|
||||
public ResponseEntity<?> GetNodeListByCondition(@RequestBody String condition){
|
||||
System.out.println(condition);
|
||||
return ResponseEntity.ok(new Response(ResponseCode.OK,"success",
|
||||
this.nodeService.GetNodeListByCondition(condition)));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.hongliang.videotask.mappers;
|
||||
|
||||
import com.hongliang.videotask.MapperProvider.NodeProvider;
|
||||
import com.hongliang.videotask.bean.NodeBean;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.SelectProvider;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -13,4 +12,7 @@ import java.util.Map;
|
||||
public interface NodeMapper {
|
||||
@SelectProvider(type= NodeProvider.class,method = "GetNodeList")
|
||||
List<NodeBean> GetNodeListByCondition(Map<String,Object> condition);
|
||||
|
||||
@SelectProvider(type=NodeProvider.class,method="GetTotal")
|
||||
int GetTotal(Map<String,Object> condition);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.hongliang.videotask.service;
|
||||
|
||||
import com.hongliang.videotask.bean.NodeBean;
|
||||
|
||||
import java.util.List;
|
||||
import com.hongliang.videotask.bean.PageResultBean;
|
||||
|
||||
public interface NodeService {
|
||||
List<NodeBean> GetNodeListByCondition(String condition);
|
||||
PageResultBean GetNodeListByCondition(String condition);
|
||||
int GetTotal(String condition);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package com.hongliang.videotask.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hongliang.videotask.bean.NodeBean;
|
||||
import com.hongliang.videotask.bean.PageResultBean;
|
||||
import com.hongliang.videotask.mappers.NodeMapper;
|
||||
import com.hongliang.videotask.service.NodeService;
|
||||
import com.hongliang.videotask.utils.CommonFuction;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -18,8 +16,19 @@ public class NodeServiceImpl implements NodeService {
|
||||
@Autowired
|
||||
private NodeMapper nodeMapper;
|
||||
|
||||
public List<NodeBean> GetNodeListByCondition(String condition){
|
||||
public PageResultBean GetNodeListByCondition(String condition){
|
||||
Map<String,Object> map= CommonFuction.JsonStringToMapWithOffset(condition);
|
||||
return this.nodeMapper.GetNodeListByCondition(map);
|
||||
List<NodeBean> list=this.nodeMapper.GetNodeListByCondition(map);
|
||||
PageResultBean<NodeBean> resultBean=new PageResultBean();
|
||||
resultBean.setList(list);
|
||||
resultBean.setPageNum(Integer.parseInt( map.get("pageNum").toString()));
|
||||
resultBean.setPageSize(Integer.parseInt(map.get("pageSize").toString()));
|
||||
resultBean.setTotal(GetTotal(condition));
|
||||
return resultBean;
|
||||
}
|
||||
|
||||
public int GetTotal(String condition){
|
||||
Map<String,Object> map= CommonFuction.JsonStringToMapWithOffset(condition);
|
||||
return this.nodeMapper.GetTotal(map);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user