废话不多:抄袭代码
package com.webank.wedatasphere.qualitis.handler;
import com.webank.wedatasphere.qualitis.response.Grid;
import com.webank.wedatasphere.qualitis.response.SelectRuleResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class CommonJDBCService {
// 公共的JDBC服务
@Autowired
private JdbcTemplate jdbcTemplate;
/**
* 分页查询 规则颗粒度---细粒自定义
*/
public Grid<?> queryRuleDataGridByPageInSqlWhere(int pageNumber, int pageSize){
String querySql = "select a.id,a.create_time,a.rule_template_name,a.cn_name,b.cluster_name,b.db_name,\n" +
"b.table_name,b.col_name,b.col_name,b.filter \n" +
"from qualitis_rule a \n" +
"left join qualitis_rule_datasource b on a.id = b.rule_id \n" +
"where a.project_id is null order by a.id asc";
String countSql= "select count(1) \n" +
"from qualitis_rule a \n" +
"left join qualitis_rule_datasource b on a.id = b.rule_id \n" +
"where a.project_id is null ";
int offset = (pageNumber - 1) * pageSize;
querySql = querySql + " limit " + offset + " , " + pageSize;
List<SelectRuleResponse> resultSets = jdbcTemplate.query(querySql, new Object[]{}, (resultSet, i) -> {
SelectRuleResponse selectRuleResponse = new SelectRuleResponse();
selectRuleResponse.setId(resultSet.getLong("id"));
selectRuleResponse.setRuleTemplateName(resultSet.getString("rule_template_name"));
selectRuleResponse.setCnName(resultSet.getString("cn_name"));
selectRuleResponse.setDatasourceName(resultSet.getString("cluster_name"));
selectRuleResponse.setDbName(resultSet.getString("db_name"));
selectRuleResponse.setTableName(resultSet.getString("table_name"));
selectRuleResponse.setTableFields(resultSet.getString("col_name"));
selectRuleResponse.setSqlWhere(resultSet.getString("filter"));
selectRuleResponse.setCreateTime(resultSet.getString("create_time"));
return selectRuleResponse;
});
Integer total = jdbcTemplate.queryForObject(countSql, Integer.class);
return Grid.OkPage(resultSets, total == null ? 0 : total);
}
}
标签:selectRuleResponse,实体类,name,自定义,集字,resultSet,rule,getString,id
From: https://www.cnblogs.com/gtnotgod/p/18033982