Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
DataSwitchSys
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
912协同工作系统
数据交换平台
DataSwitchSys
Commits
481fc0a1
提交
481fc0a1
authored
2月 26, 2020
作者:
zhangshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
zs
上级
eb3072e9
隐藏空白字符变更
内嵌
并排
正在显示
20 个修改的文件
包含
647 行增加
和
0 行删除
+647
-0
CatalogApplication.java
...ng/src/main/java/com/zjty/catalog/CatalogApplication.java
+13
-0
ResponseCode.java
...ain/java/com/zjty/catalog/base/response/ResponseCode.java
+110
-0
ServerResponse.java
...n/java/com/zjty/catalog/base/response/ServerResponse.java
+168
-0
BuildDBController.java
...n/java/com/zjty/catalog/controller/BuildDBController.java
+22
-0
BuildTableController.java
...ava/com/zjty/catalog/controller/BuildTableController.java
+22
-0
BuildTableRequest.java
.../main/java/com/zjty/catalog/domain/BuildTableRequest.java
+16
-0
Column.java
...aloging/src/main/java/com/zjty/catalog/domain/Column.java
+31
-0
DatabaseInfo.java
...g/src/main/java/com/zjty/catalog/domain/DatabaseInfo.java
+25
-0
Table.java
...taloging/src/main/java/com/zjty/catalog/domain/Table.java
+28
-0
BuildDBService.java
...rc/main/java/com/zjty/catalog/service/BuildDBService.java
+10
-0
BuildTableService.java
...main/java/com/zjty/catalog/service/BuildTableService.java
+13
-0
BuildDBServiceImpl.java
...ava/com/zjty/catalog/service/impl/BuildDBServiceImpl.java
+44
-0
BuildTableServiceImpl.java
.../com/zjty/catalog/service/impl/BuildTableServiceImpl.java
+71
-0
DBConnectionUtil.java
...rc/main/java/com/zjty/catalog/utils/DBConnectionUtil.java
+28
-0
application-dev.properties
ds-cataloging/src/main/resources/application-dev.properties
+7
-0
application-doc.properties
ds-cataloging/src/main/resources/application-doc.properties
+1
-0
application-prod.properties
ds-cataloging/src/main/resources/application-prod.properties
+1
-0
application-test.properties
ds-cataloging/src/main/resources/application-test.properties
+1
-0
application.properties
ds-cataloging/src/main/resources/application.properties
+23
-0
CatalogApplicationTests.java
...c/test/java/com/zjty/catalog/CatalogApplicationTests.java
+13
-0
没有找到文件。
ds-cataloging/src/main/java/com/zjty/catalog/CatalogApplication.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
CatalogApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
CatalogApplication
.
class
,
args
);
}
}
ds-cataloging/src/main/java/com/zjty/catalog/base/response/ResponseCode.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
.
base
.
response
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
/**
* <p>Description : 异常结果枚举类,用于统一异常状态码与相关描述信息
* @Date : 2017/12/13 0:51
* @author : M@tr!x [xhyrzldf@foxmail.com]
*/
@AllArgsConstructor
@Getter
public
enum
ResponseCode
{
/**
* 服务器成功返回用户请求的数据
*/
OK
(
200
,
"[GET]:服务器成功返回用户请求的数据,返回资源对象"
),
/**
* 用户新建或修改数据成功
*/
CREATED
(
201
,
"[POST/PUT/PATCH]:用户新建或修改数据成功,返回新生成或修改的资源对象"
),
/**
* 表示一个请求已经进入后台排队(异步任务)
*/
ACCEPTED
(
202
,
"[*]:表示一个请求已经进入后台排队(异步任务)"
),
/**
* 用户上传文件成功
*/
UPLOADED
(
203
,
"[POST]文件上传成功"
),
/**
* 用户删除数据成功
*/
NO_CONTENT
(
204
,
" [DELETE]:用户删除数据成功"
),
/**
* 用户发出的请求有错误,服务器没有进行新建或修改数据的操作
*/
INVALID_REQUEST
(
400
,
"[POST/PUT/PATCH]:用户发出的请求有错误,服务器没有进行新建或修改数据的操作"
),
/**
* 表示用户没有权限(令牌、用户名、密码错误)
*/
UNAUTHORIZED
(
401
,
" [*]:表示用户没有权限(令牌、用户名、密码错误)"
),
/**
* 表示用户登录超时
*/
LOGINOUTTIME
(
402
,
" [*]:表示用户登录超时"
),
/**
* 表示用户得到授权(与401错误相对),但是访问是被禁止的
*/
FORBIDDEN
(
403
,
" [*] 表示用户得到授权(与401错误相对),但是访问是被禁止的"
),
/**
* 用户发出的请求针对的是不存在的记录,服务器没有进行操作,该操作是幂等的
*/
NOT_FOUND
(
404
,
" [*]:用户发出的请求针对的是不存在的记录,服务器没有进行操作"
),
/**
* 非法参数,请求中附带的参数不符合要求规范
*/
ILLEGAL_PARAMETER
(
405
,
"[*]:非法参数,请求中附带的参数不符合要求规范"
),
/**
* 用户请求的格式不可得(比如用户请求JSON格式,但是只有XML格式)
*/
NOT_ACCEPTABLE
(
406
,
" [GET]:用户请求的格式不可得(比如用户请求JSON格式,但是只有XML格式)"
),
/**
* 用户的参数不得为空
*/
NOT_NULL_PARAMETER
(
408
,
"传递的参数不能为空"
),
/**
* 用户请求的资源被永久删除,且不会再得到的
*/
GONE
(
413
,
"[GET]:用户请求的资源被永久删除,且不会再得到的"
),
/**
* [PUT,PATCH,POST,DELETE]:操作没有成功,并没有数据发生变化
*/
NO_CHANGED
(
414
,
"[PUT,PATCH,POST,DELETE]:操作没有成功,并没有数据发生变化"
),
/**
* 创建一个对象时,发生一个验证错误
*/
UNPROCESSABLE_ENTITY
(
422
,
"[POST/PUT/PATCH] 当创建一个对象时,发生一个验证错误"
),
/**
* 服务器发生错误
*/
INTERNAL_SERVER_ERROR
(
500
,
"服务器发生错误"
);
/**
* 结果代码编号
*/
private
Integer
code
;
/**
* 结果信息
*/
private
String
msg
;
}
ds-cataloging/src/main/java/com/zjty/catalog/base/response/ServerResponse.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
.
base
.
response
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
lombok.Getter
;
import
static
com
.
zjty
.
catalog
.
base
.
response
.
ResponseCode
.*;
/**
* Description : 结果类,用于统一返回格式 对外提供关于响应结果的很多便利的静态方法
*
* @author : M@tr!x [xhyrzldf@foxmail.com]
* @Date : 2017/12/13 0:05
*/
@SuppressWarnings
({
"WeakerAccess"
,
"unused"
})
@Getter
public
class
ServerResponse
<
T
>
{
/**
* 错误码
*/
@JSONField
(
ordinal
=
1
)
private
Integer
code
;
/**
* 提示信息
*/
@JSONField
(
ordinal
=
2
)
private
String
msg
;
/**
* 具体的内容
*/
@JSONField
(
ordinal
=
3
)
private
T
data
;
/* 以下为返回成功响应结果的各类重载静态方法 */
public
static
<
T
>
ServerResponse
<
T
>
success
()
{
return
new
ServerResponse
<>(
OK
.
getCode
(),
OK
.
getMsg
());
}
public
static
<
T
>
ServerResponse
<
T
>
success
(
T
data
)
{
return
new
ServerResponse
<>(
OK
.
getCode
(),
OK
.
getMsg
(),
data
);
}
public
static
<
T
>
ServerResponse
<
T
>
success
(
String
msg
,
T
data
)
{
return
new
ServerResponse
<>(
OK
.
getCode
(),
msg
,
data
);
}
public
static
<
T
>
ServerResponse
<
T
>
saveSuccess
(
T
data
)
{
return
new
ServerResponse
<>(
CREATED
.
getCode
(),
CREATED
.
getMsg
(),
data
);
}
public
static
<
T
>
ServerResponse
<
T
>
deleteSuccess
()
{
return
new
ServerResponse
<>(
NO_CONTENT
.
getCode
(),
NO_CONTENT
.
getMsg
());
}
public
static
<
T
>
ServerResponse
<
T
>
deleteSuccessWithCount
(
Number
effectCount
)
{
return
new
ServerResponse
<>(
NO_CONTENT
.
getCode
(),
"删除成功,操作删除的数据条数为: "
+
effectCount
);
}
public
static
<
T
>
ServerResponse
<
T
>
deleteSuccessWithId
(
Number
id
)
{
return
new
ServerResponse
<>(
NO_CONTENT
.
getCode
(),
"删除成功,操作删除的数据id为: "
+
id
);
}
public
static
<
T
>
ServerResponse
<
T
>
uploadSuccess
(
T
data
)
{
return
new
ServerResponse
<>(
UPLOADED
.
getCode
(),
UPLOADED
.
getMsg
(),
data
);
}
public
static
<
T
>
ServerResponse
<
T
>
messageSuccess
(
String
msg
)
{
return
new
ServerResponse
<>(
OK
.
getCode
(),
msg
);
}
/* 以下为返回失败响应结果的各类重载静态方法 */
public
static
<
T
>
ServerResponse
<
T
>
error
()
{
return
new
ServerResponse
<>(
INTERNAL_SERVER_ERROR
.
getCode
(),
INTERNAL_SERVER_ERROR
.
getMsg
());
}
public
static
<
T
>
ServerResponse
<
T
>
error
(
String
errorMessage
)
{
return
new
ServerResponse
<>(
INTERNAL_SERVER_ERROR
.
getCode
(),
errorMessage
);
}
public
static
<
T
>
ServerResponse
<
T
>
error
(
ResponseCode
responseCode
)
{
return
new
ServerResponse
<>(
responseCode
.
getCode
(),
responseCode
.
getMsg
());
}
public
static
<
T
>
ServerResponse
<
T
>
error
(
ResponseCode
responseCode
,
String
errorMessage
)
{
return
new
ServerResponse
<>(
responseCode
.
getCode
(),
errorMessage
);
}
public
static
<
T
>
ServerResponse
<
T
>
error
(
ResponseCode
responseCode
,
String
errorMessage
,
T
data
)
{
return
new
ServerResponse
<>(
responseCode
.
getCode
(),
errorMessage
,
data
);
}
/* 以下为提供给CONTROL层向文件服务器操作文件获得相应结果的相关方法 */
// /**
// * <b>向文件服务器上传文件并且取得{@code {@link ServerResponse}}类型的响应结果</b>
// * <p>
// * <p>封装了control层的关于文件上传的代码
// * <p>
// * <p>例如file是a.txt,dirName=template, 在文件服务器上存放的位置就是{@code root(根目录)/template/a.txt }
// *
// * @param file {@link MultipartFile} 接受到的文件俺对象
// * @param dirName 在文件服务器上的文件夹名
// * @return {@link ServerResponse} (包含了成功与导致失败的结果)
// */
// public static ServerResponse uploadAndGet(
// @RequestParam("file") Optional<MultipartFile> file, String dirName) {
// // 空指针判断
// if (!file.isPresent()) return error(NOT_NULL_PARAMETER);
// // 上传文件并且获得相应结果
// MultipartFile uploadFile = file.get();
// FileServerResponse fsp =
// HttpClientUtil.uploadFileToServer(uploadFile, dirName, uploadFile.getOriginalFilename());
// // 根据返回结果的状态码确定相应的返回信息(200返回成功,否则error)
// return (fsp.getCode() == 200) ? uploadSuccess(fsp.getData()) : error(NO_CHANGED, fsp.getMsg());
// }
// /**
// * <b>向文件服务器删除文件并且取得{@code {@link ServerResponse}}类型的响应结果</b>
// * <p>
// * <p>封装了control层的关于文件上传的代码
// * <p>
// * <p>例如提供的参数如下
// * <li>fileName = reset-hv_20180115144834_wV9A9iVD.png
// * <li>dirName = templates
// * <li>那么实际删除的文件路径为: {@code root(根目录)/templates/reset-hv_20180115144834_wV9A9iVD.png}
// *
// * @param fileName 要删除的文件名<b>注意是文件服务器上的文件名,例如<b>reset-hv_20180115144834_wV9A9iVD.png</b> 格式为{@code
// * 原始文件名_timestamp_uuid8位}
// * @param dirName 要删除的文件所处的文件目录
// * @return {@link ServerResponse} (包含了成功与导致失败的结果)
// */
// public static ServerResponse deleteAndGet(
// @RequestParam(value = "fileName") Optional<String> fileName, String dirName) {
// // 空指针判断
// if (!fileName.isPresent()) return error(NOT_NULL_PARAMETER);
// // 发送删除文件的请求,附带文件所在的目录和在服务器中的文件名
// FileServerResponse fsp = HttpClientUtil.daleteFileToServer(dirName, fileName.get());
// // 根据返回结果的状态码确定相应的返回信息(200返回成功,否则error)
// return (fsp.getCode() == 200) ? deleteSuccess() : error(NO_CHANGED, fsp.getMsg());
// }
/* 将构造器私有,防止外部进行实例化 仅提供给内部静态方法调用 * */
private
ServerResponse
()
{
}
private
ServerResponse
(
Integer
code
)
{
this
.
code
=
code
;
}
private
ServerResponse
(
Integer
code
,
String
msg
)
{
this
.
code
=
code
;
this
.
msg
=
msg
;
}
private
ServerResponse
(
String
msg
,
T
data
)
{
this
.
msg
=
msg
;
this
.
data
=
data
;
}
private
ServerResponse
(
Integer
code
,
String
msg
,
T
data
)
{
this
.
code
=
code
;
this
.
msg
=
msg
;
this
.
data
=
data
;
}
}
ds-cataloging/src/main/java/com/zjty/catalog/controller/BuildDBController.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
.
controller
;
import
com.zjty.catalog.base.response.ServerResponse
;
import
com.zjty.catalog.domain.DatabaseInfo
;
import
com.zjty.catalog.service.BuildDBService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
"/db"
)
public
class
BuildDBController
{
@Autowired
private
BuildDBService
buildDBService
;
@PostMapping
(
"/create"
)
public
ServerResponse
buildDB
(
@RequestBody
DatabaseInfo
databaseInfo
){
return
buildDBService
.
buildDB
(
databaseInfo
);
}
}
ds-cataloging/src/main/java/com/zjty/catalog/controller/BuildTableController.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
.
controller
;
import
com.zjty.catalog.base.response.ServerResponse
;
import
com.zjty.catalog.domain.BuildTableRequest
;
import
com.zjty.catalog.service.BuildTableService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
"/table"
)
public
class
BuildTableController
{
@Autowired
private
BuildTableService
buildTableService
;
@PostMapping
(
"/create"
)
public
ServerResponse
buildTable
(
@RequestBody
BuildTableRequest
buildTableRequest
){
return
buildTableService
.
buildTableService
(
buildTableRequest
.
getDbName
(),
buildTableRequest
.
getTable
(),
buildTableRequest
.
getColumnList
());
}
}
ds-cataloging/src/main/java/com/zjty/catalog/domain/BuildTableRequest.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
.
domain
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
@AllArgsConstructor
@NoArgsConstructor
@Data
public
class
BuildTableRequest
{
private
String
dbName
;
//数据库名称
private
Table
table
;
//表
private
List
<
Column
>
columnList
;
//列集合
}
ds-cataloging/src/main/java/com/zjty/catalog/domain/Column.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
.
domain
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
@AllArgsConstructor
@NoArgsConstructor
//@Entity
@Data
public
class
Column
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
Integer
id
;
//主键
private
String
name
;
//列名
private
String
type
;
//数据类型
private
Integer
length
;
//长度
private
String
defaultName
;
//默认数据
private
Integer
primaryKey
;
//0-非主键 1-主键
private
Integer
empty
;
//0-空 1-非空
private
Integer
unsigned
;
//0-有符号 1-无符号
private
Integer
increment
;
//0-非自增 1-自增
private
Integer
zeroFill
;
//0-不补零 1-补零
private
String
note
;
//注释
private
Integer
tableId
;
//外键,所属表id
}
ds-cataloging/src/main/java/com/zjty/catalog/domain/DatabaseInfo.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
.
domain
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
java.util.Date
;
@AllArgsConstructor
@NoArgsConstructor
//@Entity
@Data
public
class
DatabaseInfo
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
Integer
id
;
private
String
name
;
//数据库名称
private
String
coding
;
//编码格式(基字符集)
private
String
collate
;
//数据库排序规则
private
Date
createTime
;
//创建时间
}
ds-cataloging/src/main/java/com/zjty/catalog/domain/Table.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
.
domain
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
java.util.Date
;
@AllArgsConstructor
@NoArgsConstructor
//@Entity
@Data
public
class
Table
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
Integer
id
;
//主键
private
String
name
;
//表名
private
String
engine
;
//引擎
private
String
coding
;
//编码格式(基字符集)
private
String
collate
;
//核对
private
Date
createTime
;
//创建时间
private
String
des
;
//备注
private
Integer
dbId
;
//所属数据库id
}
ds-cataloging/src/main/java/com/zjty/catalog/service/BuildDBService.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
.
service
;
import
com.zjty.catalog.base.response.ServerResponse
;
import
com.zjty.catalog.domain.DatabaseInfo
;
public
interface
BuildDBService
{
ServerResponse
buildDB
(
DatabaseInfo
databaseInfo
);
}
ds-cataloging/src/main/java/com/zjty/catalog/service/BuildTableService.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
.
service
;
import
com.zjty.catalog.base.response.ServerResponse
;
import
com.zjty.catalog.domain.Column
;
import
com.zjty.catalog.domain.Table
;
import
java.util.List
;
public
interface
BuildTableService
{
ServerResponse
buildTableService
(
String
dbName
,
Table
table
,
List
<
Column
>
columnList
);
}
ds-cataloging/src/main/java/com/zjty/catalog/service/impl/BuildDBServiceImpl.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
.
service
.
impl
;
import
com.zjty.catalog.base.response.ServerResponse
;
import
com.zjty.catalog.domain.DatabaseInfo
;
import
com.zjty.catalog.service.BuildDBService
;
import
com.zjty.catalog.utils.DBConnectionUtil
;
import
org.springframework.stereotype.Service
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
@Service
public
class
BuildDBServiceImpl
implements
BuildDBService
{
@Override
public
ServerResponse
buildDB
(
DatabaseInfo
databaseInfo
)
{
boolean
isSuccess
=
true
;
Connection
connection
=
DBConnectionUtil
.
databaseConnection
(
"catalog"
);
PreparedStatement
preparedStatement
=
null
;
String
sql
=
"CREATE DATABASE `"
+
databaseInfo
.
getName
()
+
"` CHARACTER SET '"
+
databaseInfo
.
getCoding
()
+
"' COLLATE '"
+
databaseInfo
.
getCollate
()
+
"';"
;
try
{
preparedStatement
=
connection
.
prepareStatement
(
sql
);
preparedStatement
.
execute
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
if
(
e
.
getMessage
().
contains
(
"database exists"
)){
isSuccess
=
false
;
}
}
finally
{
try
{
preparedStatement
.
close
();
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
if
(
isSuccess
){
return
ServerResponse
.
success
(
databaseInfo
);
}
else
{
return
ServerResponse
.
error
(
"数据库已存在"
);
}
}
}
ds-cataloging/src/main/java/com/zjty/catalog/service/impl/BuildTableServiceImpl.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
.
service
.
impl
;
import
com.zjty.catalog.base.response.ServerResponse
;
import
com.zjty.catalog.domain.Column
;
import
com.zjty.catalog.domain.Table
;
import
com.zjty.catalog.service.BuildTableService
;
import
com.zjty.catalog.utils.DBConnectionUtil
;
import
org.springframework.stereotype.Service
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
java.util.List
;
@Service
public
class
BuildTableServiceImpl
implements
BuildTableService
{
@Override
public
ServerResponse
buildTableService
(
String
dbName
,
Table
table
,
List
<
Column
>
columnList
)
{
Connection
connection
=
DBConnectionUtil
.
databaseConnection
(
dbName
);
PreparedStatement
preparedStatement
=
null
;
String
sql
=
""
;
String
startSql
=
"CREATE TABLE `"
+
dbName
+
"`.`"
+
table
.
getName
()
+
"`(\r\n"
;
String
centerSql
=
""
;
String
endSql
=
") ENGINE="
+
table
.
getEngine
()
+
" CHARSET="
+
table
.
getCoding
()
+
" COLLATE="
+
table
.
getCollate
()
+
";"
;
for
(
Column
column
:
columnList
){
centerSql
+=
"`"
+
column
.
getName
()
+
"` "
+
column
.
getType
()
+
"("
+
column
.
getLength
()
+
")"
;
if
(
column
.
getUnsigned
()
==
1
){
centerSql
+=
" UNSIGNED"
;
}
if
(
column
.
getZeroFill
()
==
1
){
centerSql
+=
" ZEROFILL"
;
}
if
(
column
.
getEmpty
()
==
1
){
centerSql
+=
" NOT NULL"
;
}
if
(
column
.
getIncrement
()
==
1
){
centerSql
+=
" AUTO_INCREMENT"
;
}
if
(
column
.
getDefaultName
()
!=
null
){
centerSql
+=
" DEFAULT '"
+
column
.
getDefaultName
()
+
"'"
;
}
if
(
column
.
getNote
()
!=
null
){
centerSql
+=
" COMMENT '"
+
column
.
getNote
()
+
"'"
;
}
if
(
column
.
getPrimaryKey
()
==
1
){
endSql
=
"PRIMARY KEY (`"
+
column
.
getName
()
+
"`)\r\n"
+
endSql
;
}
centerSql
+=
",\r\n"
;
}
sql
=
startSql
+
centerSql
+
endSql
;
System
.
out
.
println
(
sql
);
try
{
preparedStatement
=
connection
.
prepareStatement
(
sql
);
preparedStatement
.
execute
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
preparedStatement
.
close
();
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
return
ServerResponse
.
success
();
}
}
ds-cataloging/src/main/java/com/zjty/catalog/utils/DBConnectionUtil.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
.
utils
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
public
class
DBConnectionUtil
{
/**
* 数据库连接
* @param
*/
public
static
Connection
databaseConnection
(
String
dbName
){
Connection
connection
=
null
;
try
{
Class
.
forName
(
"com.mysql.cj.jdbc.Driver"
);
String
connectionUrl
=
"jdbc:mysql://localhost:3306/"
+
dbName
+
"?serverTimezone=UTC"
;
connection
=
DriverManager
.
getConnection
(
connectionUrl
,
"root"
,
"root"
);
return
connection
;
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
return
null
;
}
}
ds-cataloging/src/main/resources/application-dev.properties
0 → 100644
浏览文件 @
481fc0a1
# mysqlݿ
spring.datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
#spring.datasource.url=jdbc:mysql://192.168.1.249:3306/bservice?useSSL=false&serverTimezone=UTC&autoReconnect=true&characterEncoding=utf-8
spring.datasource.url
=
jdbc:mysql://localhost:3306/catalog?useSSL=false&serverTimezone=UTC&autoReconnect=true&characterEncoding=utf-8
spring.datasource.username
=
root
spring.datasource.password
=
root
\ No newline at end of file
ds-cataloging/src/main/resources/application-doc.properties
0 → 100644
浏览文件 @
481fc0a1
ds-cataloging/src/main/resources/application-prod.properties
0 → 100644
浏览文件 @
481fc0a1
ds-cataloging/src/main/resources/application-test.properties
0 → 100644
浏览文件 @
481fc0a1
ds-cataloging/src/main/resources/application.properties
0 → 100644
浏览文件 @
481fc0a1
# 配置文件使用 默认使用 dev 环境
spring.profiles.active
=
dev
#spring.profiles.active=doc
#spring.profiles.active=prod
# 服务器相关配置
server.port
=
8092
# 日志文件相关配置
# logging.level.org.hibernate.sql=debug
logging.file.path
=
./log/master.log
# spring-data-jpa 相关配置
# 指jpa对表生成的策略
spring.jpa.hibernate.ddl-auto
=
update
# 是否显示sql语句
spring.jpa.show-sql
=
false
# 格式化sql
spring.jpa.properties.hibernate.format_sql
=
true
spring.jpa.open-in-view
=
true
# 验证框架是否对数据操作验证
spring.jpa.properties.javax.persistence.validation.mode
=
none
\ No newline at end of file
ds-cataloging/src/test/java/com/zjty/catalog/CatalogApplicationTests.java
0 → 100644
浏览文件 @
481fc0a1
package
com
.
zjty
.
catalog
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
class
CatalogApplicationTests
{
@Test
void
contextLoads
()
{
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论