feat: 修改数据库连接
This commit is contained in:
parent
74de80bf68
commit
679f418387
|
@ -61,8 +61,8 @@
|
|||
<artifactId>HikariCP</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- lombok -->
|
||||
|
|
|
@ -2,9 +2,7 @@ package cn.bunny;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@EnableTransactionManagement
|
||||
@SpringBootApplication
|
||||
public class GeneratorCodeMainApplication {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -23,6 +23,7 @@ public class TableController {
|
|||
this.tableService = tableService;
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "获取所有表", description = "获取所有表")
|
||||
@GetMapping("getAllTableMetaData")
|
||||
public Result<List<TableInfoVo>> getAllTableMetaData() {
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.springframework.stereotype.Service;
|
|||
import java.util.List;
|
||||
|
||||
@Service
|
||||
|
||||
public class TableServiceImpl implements TableService {
|
||||
|
||||
private final DbInfoUtil dbInfoUtil;
|
||||
|
|
|
@ -3,7 +3,6 @@ package cn.bunny.utils;
|
|||
import cn.bunny.dao.entity.ColumnMetaData;
|
||||
import cn.bunny.dao.entity.TableMetaData;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
@ -19,8 +18,11 @@ import java.util.Set;
|
|||
@Component
|
||||
public class DbInfoUtil {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
private final DataSource dataSource;
|
||||
|
||||
public DbInfoUtil(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表的所有主键列名
|
||||
|
@ -29,6 +31,7 @@ public class DbInfoUtil {
|
|||
* @return 主键列名的集合
|
||||
*/
|
||||
public Set<String> getPrimaryKeyColumns(String tableName) throws SQLException {
|
||||
|
||||
Set<String> primaryKeys = new HashSet<>();
|
||||
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
|
|
|
@ -10,22 +10,8 @@ spring:
|
|||
check-template-location: false
|
||||
|
||||
datasource:
|
||||
dynamic:
|
||||
primary: master #设置默认的数据源或者数据源组,默认值即为master
|
||||
strict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
|
||||
grace-destroy: false #是否优雅关闭数据源,默认为false,设置为true时,关闭数据源时如果数据源中还存在活跃连接,至多等待10s后强制关闭
|
||||
datasource:
|
||||
master:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://${bunny.master.host}:${bunny.master.port}/${bunny.master.database}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
username: ${bunny.master.username}
|
||||
password: ${bunny.master.password}
|
||||
connect:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: org.sqlite.JDBC
|
||||
url: ${bunny.connect.url}
|
||||
username: ${bunny.connect.username}
|
||||
password: ${bunny.connect.password}
|
||||
aop:
|
||||
enabled: true
|
|
@ -6,7 +6,6 @@ import cn.bunny.dao.entity.TableMetaData;
|
|||
import cn.bunny.utils.ConvertUtil;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
@ -22,8 +21,12 @@ public class JDBCTest {
|
|||
|
||||
DatabaseMetaData metaData;
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
private final DataSource dataSource;
|
||||
|
||||
public JDBCTest(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
|
|
@ -3,7 +3,6 @@ package cn.bunny.utils;
|
|||
import cn.bunny.dao.entity.ColumnMetaData;
|
||||
import cn.bunny.dao.entity.TableMetaData;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
@ -14,8 +13,14 @@ class DbInfoUtilTest {
|
|||
|
||||
String tableName = "sys_i18n";
|
||||
|
||||
@Autowired
|
||||
private DbInfoUtil dbInfoUtil;
|
||||
// @Autowired
|
||||
// private DbInfoUtil dbInfoUtil;
|
||||
|
||||
private final DbInfoUtil dbInfoUtil;
|
||||
|
||||
public DbInfoUtilTest(DbInfoUtil dbInfoUtil) {
|
||||
this.dbInfoUtil = dbInfoUtil;
|
||||
}
|
||||
|
||||
@Test
|
||||
void tableInfo() throws SQLException {
|
||||
|
|
Loading…
Reference in New Issue