Skip to content

Commit 9d5ce1f

Browse files
committed
✨ spring-boot-demo-codegen 完成,添加jdbc前缀
1 parent 5f8ea48 commit 9d5ce1f

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

spring-boot-demo-codegen/src/main/java/com/xkcoding/codegen/constants/GenConstants.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,4 @@ public interface GenConstants {
1818
* 签名
1919
*/
2020
String SIGNATURE = "xkcoding";
21-
22-
/**
23-
* JDBC连接串前缀
24-
*/
25-
String JDBC_URL_PREFIX = "jdbc:mysql://";
2621
}

spring-boot-demo-codegen/src/main/java/com/xkcoding/codegen/entity/TableRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class TableRequest {
2525
* 每页条数
2626
*/
2727
private Integer pageSize;
28+
/**
29+
* jdbc-前缀
30+
*/
31+
private String prepend;
2832
/**
2933
* jdbc-url
3034
*/

spring-boot-demo-codegen/src/main/java/com/xkcoding/codegen/utils/DbUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.xkcoding.codegen.utils;
22

3-
import com.xkcoding.codegen.constants.GenConstants;
43
import com.xkcoding.codegen.entity.TableRequest;
54
import com.zaxxer.hikari.HikariDataSource;
65
import lombok.experimental.UtilityClass;
@@ -24,7 +23,7 @@
2423
public class DbUtil {
2524
public HikariDataSource buildFromTableRequest(TableRequest request) {
2625
HikariDataSource dataSource = new HikariDataSource();
27-
dataSource.setJdbcUrl(GenConstants.JDBC_URL_PREFIX + request.getUrl());
26+
dataSource.setJdbcUrl(request.getPrepend() + request.getUrl());
2827
dataSource.setUsername(request.getUsername());
2928
dataSource.setPassword(request.getPassword());
3029
return dataSource;

spring-boot-demo-codegen/src/main/resources/static/index.html

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ <h1>代码生成</h1>
4747
<Row :gutter="16">
4848
<i-form ref="formTableRequest" :model="tableRequest" label-position="right" label-width="50"
4949
:rules="tableRequestValidate">
50-
<i-col span="7">
50+
<i-col span="9">
5151
<form-item label="URL" prop="url" required>
52-
<i-input v-model="tableRequest.url" placeholder="格式为 <host>:<port>/<dbName>">
53-
<span slot="prepend">jdbc:mysql://</span>
52+
<i-input v-model="tableRequest.url" :placeholder="urlHint">
53+
<i-select v-model="tableRequest.prepend" slot="prepend" style="width: 150px;">
54+
<i-option value="jdbc:mysql://">jdbc:mysql://</i-option>
55+
<i-option value="jdbc:oracle:thin:@">jdbc:oracle:thin:@</i-option>
56+
<i-option value="jdbc:sqlserver://">jdbc:sqlserver://</i-option>
57+
</i-select>
5458
</i-input>
5559
</form-item>
5660
</i-col>
@@ -71,7 +75,7 @@ <h1>代码生成</h1>
7175
</form-item>
7276
</i-col>
7377

74-
<i-col span="4" style="text-align: center">
78+
<i-col span="2" style="text-align: center">
7579
<i-button type="primary" long icon="ios-search" @click="search('formTableRequest')">查询
7680
</i-button>
7781
</i-col>
@@ -184,6 +188,7 @@ <h2>生成配置</h2>
184188
tableRequest: {
185189
currentPage: 1,
186190
pageSize: 10,
191+
prepend: "",
187192
url: "",
188193
username: "",
189194
password: "",
@@ -240,6 +245,19 @@ <h2>生成配置</h2>
240245
],
241246
data: []
242247
},
248+
computed: {
249+
urlHint() {
250+
if (this.tableRequest.prepend === "jdbc:mysql://") {
251+
return "mysql格式为 <host>:<port>/<dbName>";
252+
} else if (this.tableRequest.prepend === "jdbc:oracle:thin:@") {
253+
return "oracle格式为 <host>:<port>:<SID>";
254+
} else if (this.tableRequest.prepend === "jdbc:sqlserver://") {
255+
return "sqlserver格式为 <server_name>:<port>";
256+
} else {
257+
return "请选择 JDBC Url 前缀";
258+
}
259+
}
260+
},
243261
methods: {
244262
showConfig(tableName) {
245263
this.genConfig.tableName = tableName;

0 commit comments

Comments
 (0)