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
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
153 additions
and
95 deletions
+153
-95
pom.xml
pom.xml
+77
-80
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
+1
-5
No files found.
pom.xml
View file @
8e27999a
<?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"
>
<modelVersion>
4.0.0
</modelVersion>
...
...
@@ -59,11 +60,7 @@
<artifactId>
mysql-connector-java
</artifactId>
<version>
${mysql-connector-java.version}
</version>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
<version>
${slf4j-api.version}
</version>
</dependency>
<dependency>
<groupId>
org.freemarker
</groupId>
<artifactId>
freemarker
</artifactId>
...
...
@@ -78,79 +75,79 @@
</dependencies>
<distributionManagement>
<snapshotRepository>
<id>
oss
</id>
<url>
https://oss.sonatype.org/content/repositories/snapshots/
</url>
</snapshotRepository>
<repository>
<id>
oss
</id>
<url>
https://oss.sonatype.org/service/local/staging/deploy/maven2/
</url>
</repository>
</distributionManagement>
<profiles>
<profile>
<id>
release
</id>
<build>
<plugins>
<!-- Source -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<version>
${maven-source-plugin.version}
</version>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>
jar-no-fork
</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-javadoc-plugin
</artifactId>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GPG -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-gpg-plugin
</artifactId>
<version>
${maven-gpg-plugin.version}
</version>
<executions>
<execution>
<phase>
verify
</phase>
<goals>
<goal>
sign
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<snapshotRepository>
<id>
oss
</id>
<url>
https://oss.sonatype.org/content/repositories/snapshots/
</url>
</snapshotRepository>
<repository>
<id>
oss
</id>
<url>
https://oss.sonatype.org/service/local/staging/deploy/maven2/
</url>
</repository>
</distributionManagement>
<profiles>
<profile>
<id>
release
</id>
<build>
<plugins>
<!-- Source -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<version>
${maven-source-plugin.version}
</version>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>
jar-no-fork
</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-javadoc-plugin
</artifactId>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GPG -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-gpg-plugin
</artifactId>
<version>
${maven-gpg-plugin.version}
</version>
<executions>
<execution>
<phase>
verify
</phase>
<goals>
<goal>
sign
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<!-- java编译插件 -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
${maven-compiler-plugin.version}
</version>
<configuration>
<source>
${java.version}
</source>
<target>
${java.version}
</target>
<encoding>
${project.build.sourceEncoding}
</encoding>
</configuration>
</plugin>
</plugins>
</build>
<build>
<plugins>
<!-- java编译插件 -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
${maven-compiler-plugin.version}
</version>
<configuration>
<source>
${java.version}
</source>
<target>
${java.version}
</target>
<encoding>
${project.build.sourceEncoding}
</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
src/main/java/com/github/mybatis/fl/entity/BasisInfo.java
View file @
8e27999a
...
...
@@ -69,6 +69,8 @@ public class BasisInfo implements Serializable{
private
String
controllerUrl
;
private
String
swaggerConfigUrl
;
private
String
idType
;
private
String
idJdbcType
;
...
...
@@ -94,5 +96,6 @@ public class BasisInfo implements Serializable{
this
.
serviceUrl
=
serviceUrl
;
this
.
serviceImplUrl
=
serviceImplUrl
;
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;
import
java.sql.SQLException
;
import
java.util.Date
;
import
com.github.mybatis.fl.entity.BasisInfo
;
import
com.github.mybatis.fl.util.EntityInfoUtil
;
import
com.github.mybatis.fl.util.Generator
;
...
...
@@ -47,12 +46,15 @@ public class TestMain {
bi
.
setEntityComment
(
CLASSCOMMENT
);
try
{
bi
=
EntityInfoUtil
.
getInfo
(
bi
);
String
aa1
=
Generator
.
createEntity
(
"E:\\b_test_work\\"
,
bi
).
toString
();
String
aa2
=
Generator
.
createDao
(
"E:\\b_test_work\\"
,
bi
).
toString
();
String
aa3
=
Generator
.
createDaoImpl
(
"E:\\b_test_work\\"
,
bi
).
toString
();
String
aa4
=
Generator
.
createService
(
"E:\\b_test_work\\"
,
bi
).
toString
();
String
aa5
=
Generator
.
createServiceImpl
(
"E:\\b_test_work\\"
,
bi
).
toString
();
String
aa6
=
Generator
.
createController
(
"E:\\b_test_work\\"
,
bi
).
toString
();
String
fileUrl
=
"E:\\b_test_work\\"
;
//生成文件存放位置
String
aa1
=
Generator
.
createEntity
(
fileUrl
,
bi
).
toString
();
String
aa2
=
Generator
.
createDao
(
fileUrl
,
bi
).
toString
();
String
aa3
=
Generator
.
createDaoImpl
(
fileUrl
,
bi
).
toString
();
String
aa4
=
Generator
.
createService
(
fileUrl
,
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
(
aa2
);
...
...
@@ -60,6 +62,7 @@ public class TestMain {
System
.
out
.
println
(
aa4
);
System
.
out
.
println
(
aa5
);
System
.
out
.
println
(
aa6
);
System
.
out
.
println
(
aa7
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
...
...
src/main/java/com/github/mybatis/fl/util/Generator.java
View file @
8e27999a
...
...
@@ -32,7 +32,7 @@ public class Generator {
public
static
final
String
SERVICE
=
"service"
;
public
static
final
String
SERVICE_IMPL
=
"serviceImpl"
;
public
static
final
String
CONTROLLER
=
"controller"
;
public
static
final
String
SWAGGER_CONFIG
=
"swaggerConfig"
;
//①创建实体类
public
static
JsonResult
createEntity
(
String
url
,
BasisInfo
bi
)
{
...
...
@@ -76,8 +76,12 @@ public class Generator {
String
fileUrl
=
getGeneratorFileUrl
(
url
,
bi
.
getControllerUrl
(),
bi
.
getEntityName
(),
CONTROLLER
);
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
){
if
(
type
.
equals
(
"entity"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
".java"
;
...
...
@@ -91,6 +95,8 @@ public class Generator {
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"ServiceImpl.java"
;
}
else
if
(
type
.
equals
(
"controller"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"Controller.java"
;
}
else
if
(
type
.
equals
(
"swaggerConfig"
)){
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"Config.java"
;
}
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 @@
*/
package
${
controllerUrl
};
import
com
.
item
.
util
.
JsonResult
;
import
${
entityUrl
}.${
entityName
};
import
${
serviceUrl
}.${
entityName
}
Service
;
import
org
.
springframework
.
web
.
bind
.
annotation
.
GetMapping
;
import
org
.
springframework
.
web
.
bind
.
annotation
.
PathVariable
;
import
org
.
springframework
.
web
.
bind
.
annotation
.
PostMapping
;
...
...
@@ -20,7 +17,6 @@ import org.springframework.web.bind.annotation.RestController;
import
com
.
baomidou
.
mybatisplus
.
core
.
conditions
.
query
.
QueryWrapper
;
import
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
;
import
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
;
import
io
.
swagger
.
annotations
.
Api
;
import
io
.
swagger
.
annotations
.
ApiImplicitParam
;
import
io
.
swagger
.
annotations
.
ApiImplicitParams
;
...
...
@@ -39,7 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
*
Modification
History
:
*
Date
Author
Version
Description
*---------------------------------------------------------------*
*
${
createTime
}
${
author
}
${
version
}
initialize
*
${
createTime
}
${
author
}
${
version
}
initialize
*/
@
Api
(
description
=
"${entityComment}"
,
value
=
"${entityComment}"
)
@
RestController
...
...
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