find:()增加查询数据方法 查询数据条数
parent
e127f8824f
commit
22aec6a24c
|
@ -43,7 +43,7 @@ public class ConnectController {
|
|||
if (!CollectionUtils.isEmpty(connects)){
|
||||
return Result.success(connects,"查询成功");
|
||||
}
|
||||
return Result.error(null,"暂无数据");
|
||||
return Result.success(null,"暂无数据");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,7 +58,7 @@ public class ConnectController {
|
|||
){
|
||||
return connectService.save(connect)
|
||||
?Result.success(200,"添加成功")
|
||||
:Result.error(500,"添加失败");
|
||||
:Result.success(500,"添加失败");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,7 +74,7 @@ public class ConnectController {
|
|||
){
|
||||
return connectService.updateById(connect)
|
||||
?Result.success(200,"修改成功")
|
||||
:Result.error(500,"修改失败");
|
||||
:Result.success(500,"修改失败");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,7 +102,7 @@ public class ConnectController {
|
|||
|
||||
return connectService.updInitDisable(id)
|
||||
?Result.success(200,"更改成功")
|
||||
:Result.error(500,"更改失败");
|
||||
:Result.success(500,"更改失败");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,7 +117,7 @@ public class ConnectController {
|
|||
|
||||
return connectService.updInitEnable(id)
|
||||
?Result.success(200,"更改成功")
|
||||
:Result.error(500,"更改失败");
|
||||
:Result.success(500,"更改失败");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,6 +133,6 @@ public class ConnectController {
|
|||
|
||||
return connectService.text(connect)
|
||||
?Result.success(200,"测试成功")
|
||||
:Result.error(500,"测试失败");
|
||||
:Result.success(500,"测试失败");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.server.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.server.service.DataLinkService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
*@Author:yang
|
||||
*@Package:com.muyu.server.controller
|
||||
*@Project:cloud-property
|
||||
*@name:DataLinkController
|
||||
*@Date:2024/9/7 20:12
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
public class DataLinkController {
|
||||
|
||||
private final DataLinkService dataLinkService;
|
||||
|
||||
/**
|
||||
* 查询表数据count
|
||||
* @param dataName 数据库名称
|
||||
* @param sql sql语句
|
||||
* @return 反护试图
|
||||
*/
|
||||
@PostMapping("/findCount")
|
||||
public Result<Long> findCount(String dataName,String sql){
|
||||
Long longs = dataLinkService.findCount(dataName,sql);
|
||||
return Result.success(longs);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.muyu.server.service;
|
||||
|
||||
/**
|
||||
*@Author:yang
|
||||
*@Package:com.muyu.server.service
|
||||
*@Project:cloud-property
|
||||
*@name:DataLinkService
|
||||
*@Date:2024/9/7 20:16
|
||||
*/
|
||||
public interface DataLinkService {
|
||||
|
||||
/**
|
||||
* 查询表数据count
|
||||
* @param dataName 数据库名称
|
||||
* @param sql sql语句
|
||||
* @return 反护试图
|
||||
*/
|
||||
public Long findCount(String dataName, String sql);
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.muyu.server.service.impl;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.muyu.server.service.DataLinkService;
|
||||
import com.muyu.server.util.JdbcHelper;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
*@Author:yang
|
||||
*@Package:com.muyu.server.service.impl
|
||||
*@Project:cloud-property
|
||||
*@name:DataLinkServiceImpl
|
||||
*@Date:2024/9/7 20:18
|
||||
*/
|
||||
@Service
|
||||
@Log4j2
|
||||
public class DataLinkServiceImpl implements DataLinkService {
|
||||
|
||||
/**
|
||||
* 查询表数据count
|
||||
* @param dataName 数据库名称
|
||||
* @param sql sql语句
|
||||
* @return 反护试图
|
||||
*/
|
||||
@Override
|
||||
public Long findCount(String dataName, String sql) {
|
||||
try {
|
||||
DruidDataSource connRs = JdbcHelper.getConnRs(dataName);
|
||||
assert connRs != null;
|
||||
DruidPooledConnection connection = connRs.getConnection();
|
||||
PreparedStatement ps = connection.prepareStatement(sql);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
return rs.getLong(1);
|
||||
}
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
log.error("异常信息:{}",e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue