Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
ydl-generator
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
余保谷
ydl-generator
Commits
8e27999a
Commit
8e27999a
authored
Apr 13, 2019
by
flying-cattle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加swagger配置文件自动生成
parent
03bd84cb
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
20 deletions
+78
-20
pom.xml
pom.xml
+3
-6
BasisInfo.java
src/main/java/com/github/mybatis/fl/entity/BasisInfo.java
+3
-0
TestMain.java
src/main/java/com/github/mybatis/fl/test/TestMain.java
+10
-7
Generator.java
src/main/java/com/github/mybatis/fl/util/Generator.java
+9
-3
SwaggerConfig.ftl
src/main/resources/freemarker/ftl/SwaggerConfig.ftl
+53
-0
controller.ftl
src/main/resources/freemarker/ftl/controller.ftl
+0
-4
No files found.
pom.xml
View file @
8e27999a
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
@@ -59,11 +60,7 @@
...
@@ -59,11 +60,7 @@
<artifactId>
mysql-connector-java
</artifactId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
${mysql-connector-java.version}
</version>
<version>
${mysql-connector-java.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
<version>
${slf4j-api.version}
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.freemarker
</groupId>
<groupId>
org.freemarker
</groupId>
<artifactId>
freemarker
</artifactId>
<artifactId>
freemarker
</artifactId>
...
...
src/main/java/com/github/mybatis/fl/entity/BasisInfo.java
View file @
8e27999a
...
@@ -69,6 +69,8 @@ public class BasisInfo implements Serializable{
...
@@ -69,6 +69,8 @@ public class BasisInfo implements Serializable{
private
String
controllerUrl
;
private
String
controllerUrl
;
private
String
swaggerConfigUrl
;
private
String
idType
;
private
String
idType
;
private
String
idJdbcType
;
private
String
idJdbcType
;
...
@@ -94,5 +96,6 @@ public class BasisInfo implements Serializable{
...
@@ -94,5 +96,6 @@ public class BasisInfo implements Serializable{
this
.
serviceUrl
=
serviceUrl
;
this
.
serviceUrl
=
serviceUrl
;
this
.
serviceImplUrl
=
serviceImplUrl
;
this
.
serviceImplUrl
=
serviceImplUrl
;
this
.
controllerUrl
=
controllerUrl
;
this
.
controllerUrl
=
controllerUrl
;
this
.
swaggerConfigUrl
=
controllerUrl
.
substring
(
0
,
controllerUrl
.
lastIndexOf
(
"."
))+
".config"
;
}
}
}
}
src/main/java/com/github/mybatis/fl/test/TestMain.java
View file @
8e27999a
...
@@ -8,7 +8,6 @@ package com.github.mybatis.fl.test;
...
@@ -8,7 +8,6 @@ package com.github.mybatis.fl.test;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.Date
;
import
java.util.Date
;
import
com.github.mybatis.fl.entity.BasisInfo
;
import
com.github.mybatis.fl.entity.BasisInfo
;
import
com.github.mybatis.fl.util.EntityInfoUtil
;
import
com.github.mybatis.fl.util.EntityInfoUtil
;
import
com.github.mybatis.fl.util.Generator
;
import
com.github.mybatis.fl.util.Generator
;
...
@@ -47,12 +46,15 @@ public class TestMain {
...
@@ -47,12 +46,15 @@ public class TestMain {
bi
.
setEntityComment
(
CLASSCOMMENT
);
bi
.
setEntityComment
(
CLASSCOMMENT
);
try
{
try
{
bi
=
EntityInfoUtil
.
getInfo
(
bi
);
bi
=
EntityInfoUtil
.
getInfo
(
bi
);
String
aa1
=
Generator
.
createEntity
(
"E:\\b_test_work\\"
,
bi
).
toString
();
String
fileUrl
=
"E:\\b_test_work\\"
;
//生成文件存放位置
String
aa2
=
Generator
.
createDao
(
"E:\\b_test_work\\"
,
bi
).
toString
();
String
aa1
=
Generator
.
createEntity
(
fileUrl
,
bi
).
toString
();
String
aa3
=
Generator
.
createDaoImpl
(
"E:\\b_test_work\\"
,
bi
).
toString
();
String
aa2
=
Generator
.
createDao
(
fileUrl
,
bi
).
toString
();
String
aa4
=
Generator
.
createService
(
"E:\\b_test_work\\"
,
bi
).
toString
();
String
aa3
=
Generator
.
createDaoImpl
(
fileUrl
,
bi
).
toString
();
String
aa5
=
Generator
.
createServiceImpl
(
"E:\\b_test_work\\"
,
bi
).
toString
();
String
aa4
=
Generator
.
createService
(
fileUrl
,
bi
).
toString
();
String
aa6
=
Generator
.
createController
(
"E:\\b_test_work\\"
,
bi
).
toString
();
String
aa5
=
Generator
.
createServiceImpl
(
fileUrl
,
bi
).
toString
();
String
aa6
=
Generator
.
createController
(
fileUrl
,
bi
).
toString
();
String
aa7
=
Generator
.
createSwaggerConfig
(
fileUrl
,
bi
).
toString
();
//创建swagger配置
System
.
out
.
println
(
aa1
);
System
.
out
.
println
(
aa1
);
System
.
out
.
println
(
aa2
);
System
.
out
.
println
(
aa2
);
...
@@ -60,6 +62,7 @@ public class TestMain {
...
@@ -60,6 +62,7 @@ public class TestMain {
System
.
out
.
println
(
aa4
);
System
.
out
.
println
(
aa4
);
System
.
out
.
println
(
aa5
);
System
.
out
.
println
(
aa5
);
System
.
out
.
println
(
aa6
);
System
.
out
.
println
(
aa6
);
System
.
out
.
println
(
aa7
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
...
src/main/java/com/github/mybatis/fl/util/Generator.java
View file @
8e27999a
...
@@ -32,7 +32,7 @@ public class Generator {
...
@@ -32,7 +32,7 @@ public class Generator {
public
static
final
String
SERVICE
=
"service"
;
public
static
final
String
SERVICE
=
"service"
;
public
static
final
String
SERVICE_IMPL
=
"serviceImpl"
;
public
static
final
String
SERVICE_IMPL
=
"serviceImpl"
;
public
static
final
String
CONTROLLER
=
"controller"
;
public
static
final
String
CONTROLLER
=
"controller"
;
public
static
final
String
SWAGGER_CONFIG
=
"swaggerConfig"
;
//①创建实体类
//①创建实体类
public
static
JsonResult
createEntity
(
String
url
,
BasisInfo
bi
)
{
public
static
JsonResult
createEntity
(
String
url
,
BasisInfo
bi
)
{
...
@@ -76,8 +76,12 @@ public class Generator {
...
@@ -76,8 +76,12 @@ public class Generator {
String
fileUrl
=
getGeneratorFileUrl
(
url
,
bi
.
getControllerUrl
(),
bi
.
getEntityName
(),
CONTROLLER
);
String
fileUrl
=
getGeneratorFileUrl
(
url
,
bi
.
getControllerUrl
(),
bi
.
getEntityName
(),
CONTROLLER
);
return
FreemarkerUtil
.
createFile
(
bi
,
"controller.ftl"
,
fileUrl
);
return
FreemarkerUtil
.
createFile
(
bi
,
"controller.ftl"
,
fileUrl
);
}
}
//⑥创建CONTROLLER
//生成文件
public
static
JsonResult
createSwaggerConfig
(
String
url
,
BasisInfo
bi
)
{
String
fileUrl
=
getGeneratorFileUrl
(
url
,
bi
.
getSwaggerConfigUrl
(),
"Swagger"
,
SWAGGER_CONFIG
);
return
FreemarkerUtil
.
createFile
(
bi
,
"SwaggerConfig.ftl"
,
fileUrl
);
}
//生成文件路径和名字
public
static
String
getGeneratorFileUrl
(
String
url
,
String
packageUrl
,
String
entityName
,
String
type
){
public
static
String
getGeneratorFileUrl
(
String
url
,
String
packageUrl
,
String
entityName
,
String
type
){
if
(
type
.
equals
(
"entity"
))
{
if
(
type
.
equals
(
"entity"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
".java"
;
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
".java"
;
...
@@ -91,6 +95,8 @@ public class Generator {
...
@@ -91,6 +95,8 @@ public class Generator {
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"ServiceImpl.java"
;
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"ServiceImpl.java"
;
}
else
if
(
type
.
equals
(
"controller"
))
{
}
else
if
(
type
.
equals
(
"controller"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"Controller.java"
;
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"Controller.java"
;
}
else
if
(
type
.
equals
(
"swaggerConfig"
)){
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"Config.java"
;
}
}
return
null
;
return
null
;
}
}
...
...
src/main/resources/freemarker/ftl/SwaggerConfig.ftl
0 → 100644
View file @
8e27999a
/**
*
@
filename
:${
entityName
}
Controller
${
createTime
}
*
@
project
${
project
}
${
version
}
*
Copyright
(
c
)
2020
${
author
}
Co
.
Ltd
.
*
All
right
reserved
.
*/
package
${
swaggerConfigUrl
};
import
org
.
springframework
.
context
.
annotation
.
Bean
;
import
org
.
springframework
.
context
.
annotation
.
Configuration
;
import
springfox
.
documentation
.
builders
.
ApiInfoBuilder
;
import
springfox
.
documentation
.
builders
.
PathSelectors
;
import
springfox
.
documentation
.
builders
.
RequestHandlerSelectors
;
import
springfox
.
documentation
.
service
.
ApiInfo
;
import
springfox
.
documentation
.
spi
.
DocumentationType
;
import
springfox
.
documentation
.
spring
.
web
.
plugins
.
Docket
;
import
springfox
.
documentation
.
swagger2
.
annotations
.
EnableSwagger2
;
/**
*
Swagger
核心配置文件
*
========================
*
@
author
${
author
}
*
@
Date
${
createTime
}
*
========================
*/
@
Configuration
@
EnableSwagger2
public
class
SwaggerConfig
{
public
static
String
CONTROLLER_URL
=
"${controllerUrl}"
;
//
Swagger
扫描的接口路径
public
static
String
SWAGGER_TITLE
=
"API文档-${author}"
;
//
Swagger
接口文档标题
public
static
String
SWAGGER_DESCRIPTION
=
"API文档"
;
//
Swagger
接口文档描述
public
static
String
SWAGGER_VERSION
=
"1.0"
;
//
Swagger
接口文档版本
public
static
String
SWAGGER_URL
=
"http://127.0.0.1:8080"
;
//
Swagger
项目服务的
URL
//
验证的页面
http
://
127.0.0.1
:
8080
/
swagger
-
ui
.
html
@
Bean
public
Docket
createRestApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
CONTROLLER_URL
))
.
paths
(
PathSelectors
.
any
())
.
build
();
}
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
SWAGGER_TITLE
)
.
description
(
SWAGGER_DESCRIPTION
)
.
termsOfServiceUrl
(
SWAGGER_URL
)
.
version
(
SWAGGER_VERSION
)
.
build
();
}
}
src/main/resources/freemarker/ftl/controller.ftl
View file @
8e27999a
...
@@ -6,12 +6,9 @@
...
@@ -6,12 +6,9 @@
*/
*/
package
${
controllerUrl
};
package
${
controllerUrl
};
import
com
.
item
.
util
.
JsonResult
;
import
com
.
item
.
util
.
JsonResult
;
import
${
entityUrl
}.${
entityName
};
import
${
entityUrl
}.${
entityName
};
import
${
serviceUrl
}.${
entityName
}
Service
;
import
${
serviceUrl
}.${
entityName
}
Service
;
import
org
.
springframework
.
web
.
bind
.
annotation
.
GetMapping
;
import
org
.
springframework
.
web
.
bind
.
annotation
.
GetMapping
;
import
org
.
springframework
.
web
.
bind
.
annotation
.
PathVariable
;
import
org
.
springframework
.
web
.
bind
.
annotation
.
PathVariable
;
import
org
.
springframework
.
web
.
bind
.
annotation
.
PostMapping
;
import
org
.
springframework
.
web
.
bind
.
annotation
.
PostMapping
;
...
@@ -20,7 +17,6 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -20,7 +17,6 @@ import org.springframework.web.bind.annotation.RestController;
import
com
.
baomidou
.
mybatisplus
.
core
.
conditions
.
query
.
QueryWrapper
;
import
com
.
baomidou
.
mybatisplus
.
core
.
conditions
.
query
.
QueryWrapper
;
import
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
;
import
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
;
import
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
;
import
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
;
import
io
.
swagger
.
annotations
.
Api
;
import
io
.
swagger
.
annotations
.
Api
;
import
io
.
swagger
.
annotations
.
ApiImplicitParam
;
import
io
.
swagger
.
annotations
.
ApiImplicitParam
;
import
io
.
swagger
.
annotations
.
ApiImplicitParams
;
import
io
.
swagger
.
annotations
.
ApiImplicitParams
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment