Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apidoc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
apidoc
Commits
d3cbfeaf
Commit
d3cbfeaf
authored
Jun 22, 2020
by
duanledexianxianxian
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码重构
parent
ec4188d8
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
362 additions
and
221 deletions
+362
-221
apidoc-core/build.gradle
apidoc-core/build.gradle
+1
-0
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/Context.java
...n/java/com/github/fengyuchenglun/apidoc/core/Context.java
+4
-2
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/QueryStringBuilder.java
...fengyuchenglun/apidoc/core/common/QueryStringBuilder.java
+3
-1
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ArrayTypeDescription.java
.../apidoc/core/common/description/ArrayTypeDescription.java
+3
-0
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ObjectTypeDescription.java
...apidoc/core/common/description/ObjectTypeDescription.java
+4
-2
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/PrimitiveTypeDescription.java
...doc/core/common/description/PrimitiveTypeDescription.java
+2
-0
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/StringTypeDescription.java
...apidoc/core/common/description/StringTypeDescription.java
+2
-0
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/TypeDescription.java
...nglun/apidoc/core/common/description/TypeDescription.java
+5
-3
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/UnAvailableTypeDescription.java
...c/core/common/description/UnAvailableTypeDescription.java
+2
-0
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/parser/VisitorParser.java
...thub/fengyuchenglun/apidoc/core/parser/VisitorParser.java
+17
-13
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/AsciiDocRender.java
...hub/fengyuchenglun/apidoc/core/render/AsciiDocRender.java
+1
-1
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/MarkdownRender.java
...hub/fengyuchenglun/apidoc/core/render/MarkdownRender.java
+0
-1
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/PostmanRender.java
...thub/fengyuchenglun/apidoc/core/render/PostmanRender.java
+11
-11
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Appendix.java
...om/github/fengyuchenglun/apidoc/core/schema/Appendix.java
+3
-0
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/ParameterType.java
...thub/fengyuchenglun/apidoc/core/schema/ParameterType.java
+2
-2
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Row.java
...ava/com/github/fengyuchenglun/apidoc/core/schema/Row.java
+1
-1
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Section.java
...com/github/fengyuchenglun/apidoc/core/schema/Section.java
+78
-13
apidoc-core/src/main/resources/templates/markdown.ftl
apidoc-core/src/main/resources/templates/markdown.ftl
+21
-3
apidoc-springmvc/src/main/java/com/github/fengyuchenglun/apidoc/springmvc/SpringParser.java
.../github/fengyuchenglun/apidoc/springmvc/SpringParser.java
+11
-9
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/Query.java
.../java/com/github/fengyuchenglun/example/common/Query.java
+20
-2
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/ResultData.java
.../com/github/fengyuchenglun/example/common/ResultData.java
+4
-4
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/User.java
...t/java/com/github/fengyuchenglun/example/common/User.java
+32
-21
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/spring/advanced/UserController.java
...engyuchenglun/example/spring/advanced/UserController.java
+135
-132
No files found.
apidoc-core/build.gradle
View file @
d3cbfeaf
...
@@ -3,4 +3,5 @@ dependencies {
...
@@ -3,4 +3,5 @@ dependencies {
compile
'com.fasterxml.jackson.core:jackson-databind:2.5.2'
compile
'com.fasterxml.jackson.core:jackson-databind:2.5.2'
compile
'org.asciidoctor:asciidoctorj:2.1.0'
compile
'org.asciidoctor:asciidoctorj:2.1.0'
compile
group:
'org.freemarker'
,
name:
'freemarker'
,
version:
'2.3.30'
compile
group:
'org.freemarker'
,
name:
'freemarker'
,
version:
'2.3.30'
compile
group:
'com.google.guava'
,
name:
'guava'
,
version:
'23.0'
}
}
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/Context.java
View file @
d3cbfeaf
package
com.github.fengyuchenglun.apidoc.core
;
package
com.github.fengyuchenglun.apidoc.core
;
import
com.github.fengyuchenglun.apidoc.core.common.Constants
;
import
com.github.fengyuchenglun.apidoc.core.common.Constants
;
import
com.github.fengyuchenglun.apidoc.core.render.AsciiDocRender
;
import
com.github.fengyuchenglun.apidoc.core.render.PostmanRender
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Maps
;
import
com.github.fengyuchenglun.apidoc.core.common.helper.FileHelper
;
import
com.github.fengyuchenglun.apidoc.core.common.helper.FileHelper
;
...
@@ -51,8 +53,8 @@ public class Context {
...
@@ -51,8 +53,8 @@ public class Context {
*/
*/
@Setter
@Setter
private
List
<
ProjectRender
>
renders
=
Lists
.
newArrayList
(
private
List
<
ProjectRender
>
renders
=
Lists
.
newArrayList
(
//
new AsciiDocRender(),
new
AsciiDocRender
(),
//
new PostmanRender(),
new
PostmanRender
(),
new
MarkdownRender
());
new
MarkdownRender
());
/**
/**
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/QueryStringBuilder.java
View file @
d3cbfeaf
...
@@ -2,6 +2,8 @@ package com.github.fengyuchenglun.apidoc.core.common;
...
@@ -2,6 +2,8 @@ package com.github.fengyuchenglun.apidoc.core.common;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
org.apache.commons.lang3.ClassUtils
;
import
org.apache.commons.lang3.ObjectUtils
;
import
java.util.Iterator
;
import
java.util.Iterator
;
...
@@ -15,7 +17,7 @@ public class QueryStringBuilder {
...
@@ -15,7 +17,7 @@ public class QueryStringBuilder {
}
}
builder
.
append
(
key
);
builder
.
append
(
key
);
builder
.
append
(
"="
);
builder
.
append
(
"="
);
builder
.
append
(
value
);
builder
.
append
(
ObjectUtils
.
isEmpty
(
value
)
?
"xxx"
:
value
);
return
this
;
return
this
;
}
}
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ArrayTypeDescription.java
View file @
d3cbfeaf
...
@@ -4,6 +4,7 @@ import com.github.fengyuchenglun.apidoc.core.common.ObjectMappers;
...
@@ -4,6 +4,7 @@ import com.github.fengyuchenglun.apidoc.core.common.ObjectMappers;
import
com.github.fengyuchenglun.apidoc.core.schema.Row
;
import
com.github.fengyuchenglun.apidoc.core.schema.Row
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collection
;
...
@@ -11,6 +12,7 @@ import java.util.Collection;
...
@@ -11,6 +12,7 @@ import java.util.Collection;
/**
/**
* 数组类型描述
* 数组类型描述
*/
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@Data
public
class
ArrayTypeDescription
extends
TypeDescription
{
public
class
ArrayTypeDescription
extends
TypeDescription
{
...
@@ -81,6 +83,7 @@ public class ArrayTypeDescription extends TypeDescription {
...
@@ -81,6 +83,7 @@ public class ArrayTypeDescription extends TypeDescription {
}
}
}
}
@Override
public
ArrayNode
getValue
()
{
public
ArrayNode
getValue
()
{
return
value
;
return
value
;
}
}
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ObjectTypeDescription.java
View file @
d3cbfeaf
...
@@ -5,6 +5,7 @@ import com.github.fengyuchenglun.apidoc.core.schema.Row;
...
@@ -5,6 +5,7 @@ import com.github.fengyuchenglun.apidoc.core.schema.Row;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.Setter
;
...
@@ -17,6 +18,7 @@ import java.util.List;
...
@@ -17,6 +18,7 @@ import java.util.List;
* @author fengyuchenglun
* @author fengyuchenglun
* @version 1.0.0
* @version 1.0.0
*/
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@Data
public
class
ObjectTypeDescription
extends
TypeDescription
{
public
class
ObjectTypeDescription
extends
TypeDescription
{
...
@@ -136,11 +138,11 @@ public class ObjectTypeDescription extends TypeDescription {
...
@@ -136,11 +138,11 @@ public class ObjectTypeDescription extends TypeDescription {
}
}
@Override
@Override
public
Collection
<
Row
>
rows
(
String
requestP
arameterType
)
{
public
Collection
<
Row
>
rows
(
String
p
arameterType
)
{
Collection
<
Row
>
rows
=
super
.
rows
(
null
);
Collection
<
Row
>
rows
=
super
.
rows
(
null
);
for
(
TypeDescription
member
:
members
)
{
for
(
TypeDescription
member
:
members
)
{
if
(
member
.
isAvailable
())
{
if
(
member
.
isAvailable
())
{
rows
.
addAll
(
member
.
rows
(
requestP
arameterType
));
rows
.
addAll
(
member
.
rows
(
p
arameterType
));
}
}
}
}
return
rows
;
return
rows
;
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/PrimitiveTypeDescription.java
View file @
d3cbfeaf
...
@@ -3,10 +3,12 @@ package com.github.fengyuchenglun.apidoc.core.common.description;
...
@@ -3,10 +3,12 @@ package com.github.fengyuchenglun.apidoc.core.common.description;
import
com.github.javaparser.resolution.types.ResolvedPrimitiveType
;
import
com.github.javaparser.resolution.types.ResolvedPrimitiveType
;
import
com.github.javaparser.resolution.types.ResolvedReferenceType
;
import
com.github.javaparser.resolution.types.ResolvedReferenceType
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
/**
/**
* 原始类型描述
* 原始类型描述
*/
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@Data
public
class
PrimitiveTypeDescription
extends
TypeDescription
{
public
class
PrimitiveTypeDescription
extends
TypeDescription
{
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/StringTypeDescription.java
View file @
d3cbfeaf
package
com.github.fengyuchenglun.apidoc.core.common.description
;
package
com.github.fengyuchenglun.apidoc.core.common.description
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
/**
/**
* 字符串类型
* 字符串类型
*/
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@Data
public
class
StringTypeDescription
extends
TypeDescription
{
public
class
StringTypeDescription
extends
TypeDescription
{
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/TypeDescription.java
View file @
d3cbfeaf
...
@@ -9,11 +9,13 @@ import com.google.common.collect.Lists;
...
@@ -9,11 +9,13 @@ import com.google.common.collect.Lists;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.Setter
;
import
org.apache.commons.lang3.ObjectUtils
;
import
java.util.Collection
;
import
java.util.Collection
;
/**
/**
* The type Type description.
* The type Type description.
*
* @author duanledexianxianxian
* @author duanledexianxianxian
*/
*/
@Data
@Data
...
@@ -51,7 +53,7 @@ public abstract class TypeDescription {
...
@@ -51,7 +53,7 @@ public abstract class TypeDescription {
/**
/**
* 是否必填.
* 是否必填.
*/
*/
protected
Boolean
required
=
false
;
protected
Boolean
required
=
false
;
/**
/**
* Is available boolean.
* Is available boolean.
...
@@ -173,7 +175,7 @@ public abstract class TypeDescription {
...
@@ -173,7 +175,7 @@ public abstract class TypeDescription {
*
*
* @return the collection
* @return the collection
*/
*/
public
Collection
<
Row
>
rows
(
String
requestP
arameterType
)
{
public
Collection
<
Row
>
rows
(
String
p
arameterType
)
{
String
fullKey
=
fullKey
();
String
fullKey
=
fullKey
();
if
(
StringHelper
.
isBlank
(
fullKey
))
{
if
(
StringHelper
.
isBlank
(
fullKey
))
{
return
Lists
.
newArrayList
();
return
Lists
.
newArrayList
();
...
@@ -191,7 +193,7 @@ public abstract class TypeDescription {
...
@@ -191,7 +193,7 @@ public abstract class TypeDescription {
// condition.append("required=").append(required);
// condition.append("required=").append(required);
// }
// }
return
Lists
.
newArrayList
(
new
Row
(
key
,
type
,
required
,
condition
.
toString
(),
def
,
remark
,
requestP
arameterType
));
return
Lists
.
newArrayList
(
new
Row
(
fullKey
,
type
,
required
,
condition
.
toString
(),
def
,
remark
,
p
arameterType
));
}
}
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/UnAvailableTypeDescription.java
View file @
d3cbfeaf
...
@@ -2,6 +2,7 @@ package com.github.fengyuchenglun.apidoc.core.common.description;
...
@@ -2,6 +2,7 @@ package com.github.fengyuchenglun.apidoc.core.common.description;
import
com.github.fengyuchenglun.apidoc.core.schema.Row
;
import
com.github.fengyuchenglun.apidoc.core.schema.Row
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.util.Collection
;
import
java.util.Collection
;
...
@@ -9,6 +10,7 @@ import java.util.Collection;
...
@@ -9,6 +10,7 @@ import java.util.Collection;
* 未知类型,应该忽略
* 未知类型,应该忽略
* @author duanledexianxianxian
* @author duanledexianxianxian
*/
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@Data
public
class
UnAvailableTypeDescription
extends
TypeDescription
{
public
class
UnAvailableTypeDescription
extends
TypeDescription
{
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/parser/VisitorParser.java
View file @
d3cbfeaf
...
@@ -33,16 +33,22 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
...
@@ -33,16 +33,22 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
public
void
visit
(
final
EnumDeclaration
enumDeclaration
,
final
Node
arg
)
{
public
void
visit
(
final
EnumDeclaration
enumDeclaration
,
final
Node
arg
)
{
// 访问枚举
// 访问枚举
if
(
arg
instanceof
Project
)
{
if
(
arg
instanceof
Project
)
{
Project
project
=
(
Project
)
arg
;
// Project project = (Project) arg;
// 章节
// // 章节
Chapter
chapter
=
new
Chapter
();
// Chapter chapter = new Chapter();
enumDeclaration
.
getFullyQualifiedName
().
ifPresent
(
chapter:
:
setId
);
// enumDeclaration.getFullyQualifiedName().ifPresent(chapter::setId);
chapter
.
setName
(
enumDeclaration
.
getNameAsString
());
// chapter.setName(enumDeclaration.getNameAsString());
enumDeclaration
.
getComment
().
ifPresent
(
chapter:
:
accept
);
// enumDeclaration.getComment().ifPresent(chapter::accept);
OptionalHelper
.
any
(
chapter
.
getTag
(
"book"
),
chapter
.
getTag
(
"group"
))
// OptionalHelper.any(chapter.getTag("book"), chapter.getTag("group"))
.
ifPresent
(
tag
->
chapter
.
setBookName
(
tag
.
getContent
()));
// .ifPresent(tag -> chapter.setBookName(tag.getContent()));
project
.
addChapter
(
chapter
);
// project.addChapter(chapter);
super
.
visit
(
enumDeclaration
,
chapter
);
//放入附录
if
(
enumDeclaration
.
getJavadocComment
().
isPresent
())
{
Appendix
appendix
=
Appendix
.
parse
(
enumDeclaration
.
getJavadocComment
().
get
());
ApiDoc
.
getInstance
().
getProject
().
getAppendices
().
add
(
appendix
);
}
// super.visit(enumDeclaration, chapter);
}
}
}
}
...
@@ -87,9 +93,7 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
...
@@ -87,9 +93,7 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
if
(
commentedNode
instanceof
ClassOrInterfaceDeclaration
if
(
commentedNode
instanceof
ClassOrInterfaceDeclaration
||
commentedNode
instanceof
EnumDeclaration
)
{
||
commentedNode
instanceof
EnumDeclaration
)
{
Appendix
appendix
=
Appendix
.
parse
(
javadocComment
);
Appendix
appendix
=
Appendix
.
parse
(
javadocComment
);
if
(
appendix
!=
null
)
{
ApiDoc
.
getInstance
().
getProject
().
getAppendices
().
add
(
appendix
);
ApiDoc
.
getInstance
().
getProject
().
getAppendices
().
add
(
appendix
);
}
}
}
}
}
});
});
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/AsciiDocRender.java
View file @
d3cbfeaf
...
@@ -74,7 +74,7 @@ public class AsciiDocRender implements ProjectRender {
...
@@ -74,7 +74,7 @@ public class AsciiDocRender implements ProjectRender {
section
.
getInHeaders
().
values
().
forEach
(
header
->
builder
.
textLine
(
header
.
toString
()));
section
.
getInHeaders
().
values
().
forEach
(
header
->
builder
.
textLine
(
header
.
toString
()));
if
(
section
.
hasRequestBody
())
{
if
(
section
.
hasRequestBody
())
{
b
.
br
();
b
.
br
();
b
.
text
(
section
.
getParameterString
());
b
.
text
(
section
.
get
RequestBody
ParameterString
());
}
}
},
"source,HTTP"
);
},
"source,HTTP"
);
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/MarkdownRender.java
View file @
d3cbfeaf
...
@@ -43,7 +43,6 @@ public class MarkdownRender implements ProjectRender {
...
@@ -43,7 +43,6 @@ public class MarkdownRender implements ProjectRender {
}
}
private
void
build
(
Project
project
)
throws
Exception
{
private
void
build
(
Project
project
)
throws
Exception
{
System
.
out
.
println
(
project
);
String
templatePath
=
ApiDoc
.
getInstance
().
getContext
().
getMarkdownTemplate
();
String
templatePath
=
ApiDoc
.
getInstance
().
getContext
().
getMarkdownTemplate
();
String
id
=
ApiDoc
.
getInstance
().
getContext
().
getId
();
String
id
=
ApiDoc
.
getInstance
().
getContext
().
getId
();
Path
buildPath
=
ApiDoc
.
getInstance
().
getContext
().
getBuildPath
();
Path
buildPath
=
ApiDoc
.
getInstance
().
getContext
().
getBuildPath
();
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/PostmanRender.java
View file @
d3cbfeaf
...
@@ -74,18 +74,18 @@ public class PostmanRender implements ProjectRender {
...
@@ -74,18 +74,18 @@ public class PostmanRender implements ProjectRender {
request
.
setMethod
(
section
.
getMethod
());
request
.
setMethod
(
section
.
getMethod
());
request
.
getHeaders
().
addAll
(
section
.
getInHeaders
().
values
());
request
.
getHeaders
().
addAll
(
section
.
getInHeaders
().
values
());
ObjectNode
objectNode
=
(
ObjectNode
)
section
.
getQueryParameters
();
for
(
String
key
:
section
.
getRequestRows
().
keySet
())
{
if
(
objectNode
.
has
(
key
))
{
Row
row
=
section
.
getRequestRows
().
get
(
key
);
request
.
getUrl
().
getQuery
().
add
(
Parameter
.
of
(
row
));
}
}
if
(
section
.
isQueryParameter
())
{
if
(
section
.
isQueryParameter
())
{
if
(
Method
.
GET
.
equals
(
request
.
getMethod
()))
{
// get请求
ObjectNode
objectNode
=
(
ObjectNode
)
section
.
getParameter
();
if
(!
Method
.
GET
.
equals
(
request
.
getMethod
()))
{
for
(
String
key
:
section
.
getRequestRows
().
keySet
())
{
if
(
objectNode
.
has
(
key
))
{
Row
row
=
section
.
getRequestRows
().
get
(
key
);
request
.
getUrl
().
getQuery
().
add
(
Parameter
.
of
(
row
));
}
}
}
else
{
request
.
getBody
().
setMode
(
BodyMode
.
urlencoded
);
request
.
getBody
().
setMode
(
BodyMode
.
urlencoded
);
ObjectNode
objectNode
=
(
ObjectNode
)
section
.
getParameter
();
objectNode
=
(
ObjectNode
)
section
.
getRequestBodyParameters
();
for
(
String
key
:
section
.
getRequestRows
().
keySet
())
{
for
(
String
key
:
section
.
getRequestRows
().
keySet
())
{
if
(
objectNode
.
has
(
key
))
{
if
(
objectNode
.
has
(
key
))
{
Row
row
=
section
.
getRequestRows
().
get
(
key
);
Row
row
=
section
.
getRequestRows
().
get
(
key
);
...
@@ -95,7 +95,7 @@ public class PostmanRender implements ProjectRender {
...
@@ -95,7 +95,7 @@ public class PostmanRender implements ProjectRender {
}
}
}
else
{
}
else
{
request
.
getBody
().
setMode
(
BodyMode
.
raw
);
request
.
getBody
().
setMode
(
BodyMode
.
raw
);
request
.
getBody
().
setRaw
(
section
.
getParameterString
());
request
.
getBody
().
setRaw
(
section
.
get
RequestBody
ParameterString
());
}
}
item
.
setRequest
(
request
);
item
.
setRequest
(
request
);
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Appendix.java
View file @
d3cbfeaf
package
com.github.fengyuchenglun.apidoc.core.schema
;
package
com.github.fengyuchenglun.apidoc.core.schema
;
import
com.github.javaparser.ast.body.BodyDeclaration
;
import
com.github.javaparser.ast.body.BodyDeclaration
;
import
com.github.javaparser.ast.body.EnumDeclaration
;
import
com.github.javaparser.ast.comments.JavadocComment
;
import
com.github.javaparser.ast.comments.JavadocComment
;
import
com.github.javaparser.ast.nodeTypes.NodeWithSimpleName
;
import
com.github.javaparser.ast.nodeTypes.NodeWithSimpleName
;
import
com.github.fengyuchenglun.apidoc.core.common.helper.EnumHelper
;
import
com.github.fengyuchenglun.apidoc.core.common.helper.EnumHelper
;
...
@@ -35,6 +36,8 @@ public class Appendix extends Node {
...
@@ -35,6 +36,8 @@ public class Appendix extends Node {
return
cells
.
isEmpty
();
return
cells
.
isEmpty
();
}
}
/**
/**
* Parse appendix.
* Parse appendix.
*
*
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/
Request
ParameterType.java
→
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/ParameterType.java
View file @
d3cbfeaf
...
@@ -7,7 +7,7 @@ package com.github.fengyuchenglun.apidoc.core.schema;
...
@@ -7,7 +7,7 @@ package com.github.fengyuchenglun.apidoc.core.schema;
* @date 2020 /3/29 0:37
* @date 2020 /3/29 0:37
* @since 1.0.0
* @since 1.0.0
*/
*/
public
enum
Request
ParameterType
{
public
enum
ParameterType
{
/**
/**
* 查询参数.
* 查询参数.
*/
*/
...
@@ -29,7 +29,7 @@ public enum RequestParameterType {
...
@@ -29,7 +29,7 @@ public enum RequestParameterType {
*/
*/
private
String
msg
;
private
String
msg
;
Request
ParameterType
(
String
code
,
String
msg
)
{
ParameterType
(
String
code
,
String
msg
)
{
this
.
code
=
code
;
this
.
code
=
code
;
this
.
msg
=
msg
;
this
.
msg
=
msg
;
}
}
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Row.java
View file @
d3cbfeaf
...
@@ -42,7 +42,7 @@ public class Row {
...
@@ -42,7 +42,7 @@ public class Row {
/**
/**
* 请求参数类型
* 请求参数类型
*/
*/
String
requestP
arameterType
;
String
p
arameterType
;
/**
/**
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Section.java
View file @
d3cbfeaf
...
@@ -20,7 +20,7 @@ import java.util.*;
...
@@ -20,7 +20,7 @@ import java.util.*;
* @version 1.0.0
* @version 1.0.0
*/
*/
@Data
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
@EqualsAndHashCode
(
callSuper
=
true
)
public
class
Section
extends
Node
{
public
class
Section
extends
Node
{
/**
/**
...
@@ -39,14 +39,24 @@ public class Section extends Node {
...
@@ -39,14 +39,24 @@ public class Section extends Node {
* 路径变量.
* 路径变量.
*/
*/
ObjectNode
pathVariable
=
ObjectMappers
.
instance
.
createObjectNode
();
ObjectNode
pathVariable
=
ObjectMappers
.
instance
.
createObjectNode
();
/**
* The Parameter.
*/
JsonNode
parameter
;
/**
/**
* The Query parameter.
* The Query parameter.
*/
*/
boolean
queryParameter
=
true
;
boolean
queryParameter
=
true
;
/**
* 查询参数+请求体参数
*/
JsonNode
parameters
=
ObjectMappers
.
instance
.
createObjectNode
();
/**
* 查询参数
*/
JsonNode
queryParameters
=
ObjectMappers
.
instance
.
createObjectNode
();
/**
* 请求体参数
*/
JsonNode
requestBodyParameters
=
ObjectMappers
.
instance
.
createObjectNode
();
/**
/**
* The Request rows.
* The Request rows.
*/
*/
...
@@ -68,6 +78,38 @@ public class Section extends Node {
...
@@ -68,6 +78,38 @@ public class Section extends Node {
*/
*/
Object
rawResponse
;
Object
rawResponse
;
/**
* Sets parameter.
*
* @param parameter the parameter
*/
public
void
setParameters
(
JsonNode
parameter
)
{
((
ObjectNode
)
this
.
parameters
).
setAll
((
ObjectNode
)
parameter
);
}
/**
* Sets query parameters.
*
* @param parameter the parameter
*/
public
void
setQueryParameters
(
JsonNode
parameter
)
{
((
ObjectNode
)
this
.
queryParameters
).
setAll
((
ObjectNode
)
parameter
);
}
/**
* Sets request body parameters.
*
* @param parameter the parameter
*/
public
void
setRequestBodyParameters
(
JsonNode
parameter
)
{
((
ObjectNode
)
this
.
requestBodyParameters
).
setAll
((
ObjectNode
)
parameter
);
}
/**
* Sets uri.
*
* @param uri the uri
*/
public
void
setUri
(
String
uri
)
{
public
void
setUri
(
String
uri
)
{
String
value
=
""
;
String
value
=
""
;
if
(
StringUtils
.
isNotBlank
(
uri
))
{
if
(
StringUtils
.
isNotBlank
(
uri
))
{
...
@@ -106,8 +148,8 @@ public class Section extends Node {
...
@@ -106,8 +148,8 @@ public class Section extends Node {
public
String
getRequestLine
()
{
public
String
getRequestLine
()
{
StringBuilder
builder
=
new
StringBuilder
(
this
.
method
.
toString
());
StringBuilder
builder
=
new
StringBuilder
(
this
.
method
.
toString
());
builder
.
append
(
" "
).
append
(
this
.
uri
);
builder
.
append
(
" "
).
append
(
this
.
uri
);
if
(
this
.
queryParameter
&&
Objects
.
equals
(
"GET"
,
this
.
method
))
{
if
(
Objects
.
equals
(
"GET"
,
this
.
method
))
{
String
parameterString
=
getParameterString
();
String
parameterString
=
get
Query
ParameterString
();
if
(
StringHelper
.
nonBlank
(
parameterString
))
{
if
(
StringHelper
.
nonBlank
(
parameterString
))
{
builder
.
append
(
"?"
).
append
(
parameterString
);
builder
.
append
(
"?"
).
append
(
parameterString
);
}
}
...
@@ -116,16 +158,39 @@ public class Section extends Node {
...
@@ -116,16 +158,39 @@ public class Section extends Node {
return
builder
.
toString
();
return
builder
.
toString
();
}
}
/**
/**
* Get
parameter string
string.
* Get
s query parameter
string.
*
*
* @return the string
* @return the
query parameter
string
*/
*/
public
String
getParameterString
()
{
public
String
getParameterString
()
{
if
(
queryParameter
&&
parameter
instanceof
ObjectNode
)
{
if
(
queryParameter
)
{
return
new
QueryStringBuilder
().
append
((
ObjectNode
)
parameter
).
toString
();
// 查询参数
new
QueryStringBuilder
().
append
((
ObjectNode
)
queryParameters
).
toString
();
}
}
return
ObjectMappers
.
pretty
(
parameter
);
// 请求体参数
return
ObjectMappers
.
pretty
(
parameters
);
}
/**
* Gets query parameter string.
*
* @return the query parameter string
*/
public
String
getQueryParameterString
()
{
return
new
QueryStringBuilder
().
append
((
ObjectNode
)
queryParameters
).
toString
();
}
/**
* Gets request body parameter string.
*
* @return the request body parameter string
*/
public
String
getRequestBodyParameterString
()
{
// 请求体参数
return
ObjectMappers
.
pretty
(
requestBodyParameters
);
}
}
/**
/**
...
@@ -137,7 +202,7 @@ public class Section extends Node {
...
@@ -137,7 +202,7 @@ public class Section extends Node {
if
(
Objects
.
equals
(
"GET"
,
this
.
method
))
{
if
(
Objects
.
equals
(
"GET"
,
this
.
method
))
{
return
false
;
return
false
;
}
}
return
parameter
!=
null
&&
parameter
.
size
()
>
0
;
return
requestBodyParameters
!=
null
&&
requestBodyParameters
.
size
()
>
0
;
}
}
/**
/**
...
...
apidoc-core/src/main/resources/templates/markdown.ftl
View file @
d3cbfeaf
...
@@ -46,9 +46,13 @@ ${section.method} ${section.uri!''} HTTP/1.1
...
@@ -46,9 +46,13 @@ ${section.method} ${section.uri!''} HTTP/1.1
${inHeaderValue!''}
${inHeaderValue!''}
</#list>
</#list>
</#if>
</#if>
<#if section.hasRequestBody(
)>
<#if (section.getQueryParameterString()?length gt 1
)>
${section.getParameterString()}
${section.getQueryParameterString()}
</#if>
<#if section.hasRequestBody()>
${section.getRequestBodyParameterString()}
</#if>
</#if>
```
```
<#-- 请求参数table列表-->
<#-- 请求参数table列表-->
...
@@ -57,7 +61,7 @@ ${section.getParameterString()}
...
@@ -57,7 +61,7 @@ ${section.getParameterString()}
| 字段 | 类型 | 参数类型 | 是否必填 | 验证 | 默认值 | 描述 |
| 字段 | 类型 | 参数类型 | 是否必填 | 验证 | 默认值 | 描述 |
| :------- | :----- | :----- |:-------- |:-------- | :------ | :---------- |
| :------- | :----- | :----- |:-------- |:-------- | :------ | :---------- |
<#list section.requestRows as rowKey,rowValue>
<#list section.requestRows as rowKey,rowValue>
| ${rowValue.key!''} | ${rowValue.type!''} | **${rowValue.
requestP
arameterType!''}** |${rowValue.required?string('true','false')} | ${rowValue.condition!''} | ${rowValue.def!''} | ${rowValue.remark!''} |
| ${rowValue.key!''} | ${rowValue.type!''} | **${rowValue.
p
arameterType!''}** |${rowValue.required?string('true','false')} | ${rowValue.condition!''} | ${rowValue.def!''} | ${rowValue.remark!''} |
</#list>
</#list>
</#if>
</#if>
<#-- 响应-->
<#-- 响应-->
...
@@ -85,3 +89,17 @@ ${section.getResponseString()}
...
@@ -85,3 +89,17 @@ ${section.getResponseString()}
</#list>
</#list>
<#------------ END 循环遍历book ---------->
<#------------ END 循环遍历book ---------->
</#if>
</#if>
# 附录
<#if appendices??>
<#list appendices as appendfix>
## ${appendfix.name}
<#if appendfix.cells?? && (appendfix.cells?size>0)>
| 编码 | 值 | 说明 |
| :------- | :----- |:-----
<#list appendfix.cells as cell>
| <#if (cell.values?size>0)>${cell.values[0]}</#if> | <#if (cell.values?size>1)>${cell.values[1]}</#if> | <#if (cell.values?size>2)>${cell.values[2]}</#if> |
</#list>
</#if>
</#list >
</#if>
apidoc-springmvc/src/main/java/com/github/fengyuchenglun/apidoc/springmvc/SpringParser.java
View file @
d3cbfeaf
...
@@ -24,7 +24,7 @@ import com.github.fengyuchenglun.apidoc.springmvc.resovler.SpringComponentTypeRe
...
@@ -24,7 +24,7 @@ import com.github.fengyuchenglun.apidoc.springmvc.resovler.SpringComponentTypeRe
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
import
static
com
.
github
.
fengyuchenglun
.
apidoc
.
core
.
schema
.
Request
ParameterType
.*;
import
static
com
.
github
.
fengyuchenglun
.
apidoc
.
core
.
schema
.
ParameterType
.*;
/**
/**
...
@@ -141,10 +141,12 @@ public class SpringParser implements ParserStrategy {
...
@@ -141,10 +141,12 @@ public class SpringParser implements ParserStrategy {
* @param section the section
* @param section the section
*/
*/
private
void
visitParameters
(
MethodDeclaration
n
,
Chapter
chapter
,
Section
section
)
{
private
void
visitParameters
(
MethodDeclaration
n
,
Chapter
chapter
,
Section
section
)
{
if
(
ParameterHelper
.
hasRequestBody
(
n
.
getParameters
()))
{
for
(
Parameter
parameter
:
n
.
getParameters
())
{
visitRequestBody
(
n
,
chapter
,
section
);
if
(
ParameterHelper
.
isRequestBody
(
parameter
))
{
}
else
{
visitRequestBody
(
n
,
chapter
,
section
);
visitParameter
(
n
,
chapter
,
section
);
}
else
{
visitParameter
(
n
,
chapter
,
section
);
}
}
}
}
}
...
@@ -160,7 +162,7 @@ public class SpringParser implements ParserStrategy {
...
@@ -160,7 +162,7 @@ public class SpringParser implements ParserStrategy {
if
(
ParameterHelper
.
isPathVariable
(
parameter
))
{
if
(
ParameterHelper
.
isPathVariable
(
parameter
))
{
section
.
getPathVariable
().
put
(
parameter
.
getNameAsString
(),
""
);
section
.
getPathVariable
().
put
(
parameter
.
getNameAsString
(),
""
);
Row
row
=
new
Row
();
Row
row
=
new
Row
();
row
.
set
Request
ParameterType
(
PATH
.
getMsg
());
row
.
setParameterType
(
PATH
.
getMsg
());
row
.
setKey
(
parameter
.
getNameAsString
());
row
.
setKey
(
parameter
.
getNameAsString
());
row
.
setType
(
parameter
.
getType
().
toString
());
row
.
setType
(
parameter
.
getType
().
toString
());
// 路径参数必填
// 路径参数必填
...
@@ -235,9 +237,9 @@ public class SpringParser implements ParserStrategy {
...
@@ -235,9 +237,9 @@ public class SpringParser implements ParserStrategy {
TypeDescription
description
=
ApiDoc
.
getInstance
().
getTypeResolvers
().
resolve
(
parameter
.
getType
());
TypeDescription
description
=
ApiDoc
.
getInstance
().
getTypeResolvers
().
resolve
(
parameter
.
getType
());
if
(
description
.
isAvailable
())
{
if
(
description
.
isAvailable
())
{
if
(
description
.
isArray
())
{
if
(
description
.
isArray
())
{
section
.
set
Parameter
(
description
.
asArray
().
getValue
());
section
.
set
RequestBodyParameters
(
description
.
asArray
().
getValue
());
}
else
if
(
description
.
isObject
())
{
}
else
if
(
description
.
isObject
())
{
section
.
set
Parameter
(
description
.
asObject
().
getValue
());
section
.
set
RequestBodyParameters
(
description
.
asObject
().
getValue
());
}
}
section
.
addRequestRows
(
description
.
rows
(
BODY
.
getMsg
()));
section
.
addRequestRows
(
description
.
rows
(
BODY
.
getMsg
()));
}
}
...
@@ -299,7 +301,7 @@ public class SpringParser implements ParserStrategy {
...
@@ -299,7 +301,7 @@ public class SpringParser implements ParserStrategy {
}
}
}
}
}
}
section
.
set
Parameter
(
objectTypeDescription
.
getValue
());
section
.
set
QueryParameters
(
objectTypeDescription
.
getValue
());
section
.
addRequestRows
(
objectTypeDescription
.
rows
(
QUERY
.
getMsg
()));
section
.
addRequestRows
(
objectTypeDescription
.
rows
(
QUERY
.
getMsg
()));
}
}
...
...
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/Query.java
View file @
d3cbfeaf
...
@@ -3,6 +3,8 @@ package com.github.fengyuchenglun.example.common;
...
@@ -3,6 +3,8 @@ package com.github.fengyuchenglun.example.common;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.Setter
;
import
java.time.LocalDateTime
;
@Setter
@Setter
@Getter
@Getter
public
class
Query
{
public
class
Query
{
...
@@ -13,8 +15,24 @@ public class Query {
...
@@ -13,8 +15,24 @@ public class Query {
public
static
final
String
CONSTANS
=
""
;
public
static
final
String
CONSTANS
=
""
;
/**
/**
* 查询关键字
* 用户名称
*/
private
String
userName
;
/**
* 用户手机号码
*/
private
String
userPhoneNum
;
/**
* 用户邮箱
*/
private
String
userEmail
;
/**
* 开始时间
*/
private
LocalDateTime
startTime
;
/**
* 结束时间
*/
*/
String
q
=
"123"
;
private
LocalDateTime
endTime
;
}
}
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/ResultData.java
View file @
d3cbfeaf
...
@@ -4,7 +4,7 @@ import lombok.Getter;
...
@@ -4,7 +4,7 @@ import lombok.Getter;
import
lombok.Setter
;
import
lombok.Setter
;
/**
/**
*
The type Result data
.
*
统一返回结果对象
.
*
*
* @param <T> the type parameter
* @param <T> the type parameter
* @author fengyuchenglun
* @author fengyuchenglun
...
@@ -25,7 +25,7 @@ public class ResultData<T> {
...
@@ -25,7 +25,7 @@ public class ResultData<T> {
//返回信息
//返回信息
String
msg
;
String
msg
;
/**
/**
*
The Data
.
*
数据对象
.
*/
*/
T
data
;
T
data
;
...
@@ -35,7 +35,7 @@ public class ResultData<T> {
...
@@ -35,7 +35,7 @@ public class ResultData<T> {
* @param <T> the type parameter
* @param <T> the type parameter
* @return the result data
* @return the result data
*/
*/
public
static
<
T
>
ResultData
<
T
>
ok
(){
public
static
<
T
>
ResultData
<
T
>
ok
()
{
return
ok
(
null
);
return
ok
(
null
);
}
}
...
@@ -46,7 +46,7 @@ public class ResultData<T> {
...
@@ -46,7 +46,7 @@ public class ResultData<T> {
* @param data the data
* @param data the data
* @return the result data
* @return the result data
*/
*/
public
static
<
T
>
ResultData
<
T
>
ok
(
T
data
){
public
static
<
T
>
ResultData
<
T
>
ok
(
T
data
)
{
ResultData
<
T
>
resultData
=
new
ResultData
<>();
ResultData
<
T
>
resultData
=
new
ResultData
<>();
resultData
.
code
=
0
;
resultData
.
code
=
0
;
resultData
.
msg
=
"ok"
;
resultData
.
msg
=
"ok"
;
...
...
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/User.java
View file @
d3cbfeaf
...
@@ -8,6 +8,7 @@ import javax.validation.constraints.Min;
...
@@ -8,6 +8,7 @@ import javax.validation.constraints.Min;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.NotNull
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
/**
/**
* 用户对象
* 用户对象
...
@@ -19,30 +20,40 @@ import java.util.Date;
...
@@ -19,30 +20,40 @@ import java.util.Date;
@Getter
@Getter
public
class
User
{
public
class
User
{
// /**
// * 用户编号.
// */
// int id;
// /**
// * 用户名称.
// */
// @NotBlank
// String name;
// /**
// * 用户年龄.
// */
// @Min(1)
// @NotNull
// Integer age;
// /**
// * 创建时间.
// */
// Date createAt;
// /**
// * 性别.
// */
// @NotBlank
// @JsonProperty("Sex")
// String sex;
/**
/**
* 用户编号.
* 用户.
*/
int
id
;
/**
* 用户名称.
*/
@NotBlank
String
name
;
/**
* 用户年龄.
*/
@Min
(
1
)
@NotNull
Integer
age
;
/**
* 创建时间.
*/
*/
Date
createAt
;
private
UserQuery
query
;
/**
/**
*
性别
.
*
用户
.
*/
*/
@NotBlank
private
List
<
Menu
>
menus
;
@JsonProperty
(
"Sex"
)
String
sex
;
}
}
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/spring/advanced/UserController.java
View file @
d3cbfeaf
package
com.github.fengyuchenglun.example.spring.advanced
;
package
com.github.fengyuchenglun.example.spring.advanced
;
import
com.github.fengyuchenglun.example.annotation.KimController
;
import
com.github.fengyuchenglun.example.common.Query
;
import
com.github.fengyuchenglun.example.common.Query
;
import
com.github.fengyuchenglun.example.common.User
;
import
com.github.fengyuchenglun.example.common.User
;
import
com.github.fengyuchenglun.example.common.UserQuery
;
import
com.github.fengyuchenglun.example.common.UserQuery
;
...
@@ -8,6 +7,7 @@ import lombok.Data;
...
@@ -8,6 +7,7 @@ import lombok.Data;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.List
;
/**
/**
* 用户接口.
* 用户接口.
...
@@ -18,138 +18,141 @@ import java.io.Serializable;
...
@@ -18,138 +18,141 @@ import java.io.Serializable;
* @index 20
* @index 20
* @since 1.0.0
* @since 1.0.0
*/
*/
@
Kim
Controller
@
Rest
Controller
@RequestMapping
(
"/api/v1/users"
)
@RequestMapping
(
"/api/v1/users"
)
public
class
UserController
{
public
class
UserController
{
//
/**
// /**
* 查看用户详情
// * 查看用户详情
*
// *
* @param userId 用户编号
// * @param userId 用户编号
* @param query 过滤条件
// * @param age 年龄
* @return 用户对象 user
// * @param query 过滤条件
*/
// * @return 用户对象 user
@GetMapping
(
value
=
"/{userId}"
)
// */
public
User
detail
(
@PathVariable
String
userId
,
Query
query
)
{
// @PostMapping(value = "/{userId}")
User
user
=
new
User
();
// public User detail(@PathVariable String userId, String age, @RequestBody Query query) {
return
user
;
// User user = new User();
}
// return user;
// }
/**
//
* 查看用户详情
// /**
*
// * 查看用户详情
* @param query 过滤条件
// * 测试get的query对象
* @return 用户对象 user
// *
*/
// * @param query 过滤条件
@GetMapping
(
value
=
"/detail1"
)
// * @return 用户对象 user
public
User
detail1
(
Query
query
)
{
// */
User
user
=
new
User
();
// @GetMapping(value = "/detail1")
return
user
;
// public User detail1(Query query) {
}
// User user = new User();
// return user;
/**
// }
* 查看用户详情
//
*
//
* @param query 过滤条件
// /**
* @return 用户对象 user
// * 测试get的query对象,带RequestParam注解
*/
// *
@GetMapping
(
value
=
"/detail3"
)
// * @param query 过滤条件
public
User
detail3
(
@RequestParam
Query
query
)
{
// * @return 用户对象 user
User
user
=
new
User
();
// */
return
user
;
// @GetMapping(value = "/detail3")
}
// public User detail3(@RequestParam String query) {
// User user = new User();
/**
// return user;
* 查看用户详情
// }
*
//
* @param query 过滤条件
// /**
* @return 用户对象 user
// * 测试get的query对象,带RequestParam注解,required=false
*/
// *
@GetMapping
(
value
=
"/detail4"
)
// * @param query 过滤条件
public
User
detail4
(
@RequestParam
(
required
=
false
)
Query
query
)
{
// * @return 用户对象 user
User
user
=
new
User
();
// */
return
user
;
// @GetMapping(value = "/detail4")
}
// public User detail4(@RequestParam(required = false) String query) {
// User user = new User();
/**
// return user;
* 查看用户详情
// }
*
//
* @return 用户对象 user
// /**
*/
// * get-无查询参数
@GetMapping
(
value
=
"/detail5"
)
// *
public
User
detail5
()
{
// * @return 用户对象 user
User
user
=
new
User
();
// */
return
user
;
// @GetMapping(value = "/detail5")
}
// public List<User> detail5() {
// return null;
/**
// }
* 查看用户详情
//
*
// /**
* @param userName the user name
// * get-原始对象+查询对象
* @param age the age
// *
* @param query the query
// * @param userName the user name
* @return 用户对象 user
// * @param age the age
*/
// * @param query the query
@GetMapping
(
value
=
"/detail6"
)
// * @return 用户对象 user
public
User
detail6
(
String
userName
,
Integer
age
,
UserQuery
query
)
{
// */
User
user
=
new
User
();
// @GetMapping(value = "/detail6")
return
user
;
// public User detail6(String userName, Integer age, UserQuery query) {
}
// User user = new User();
// return user;
/**
// }
* 查看用户详情
//
*
// /**
* @return 用户对象 user
// * post-
*/
// *
@GetMapping
(
value
=
"/detail7"
)
// * @return 用户对象 user
public
void
detail7
()
{
// */
}
// @GetMapping(value = "/post1")
// public UserQuery post1() {
// return null;
/**
// }
* 删除用户
//
*
//
* @param userId the user id
// /**
* @return boolean 是否成功
// * 删除用户
*/
// *
@DeleteMapping
(
value
=
"/{userId}"
)
// * @param userId the user id
public
Boolean
deleteUser
(
@PathVariable
(
"userId"
)
Long
userId
)
{
// * @return boolean 是否成功
return
true
;
// */
}
// @DeleteMapping(value = "/{userId}")
// public Boolean deleteUser(@PathVariable("userId") Long userId) {
// return true;
/**
// }
* 用户表单对象.
//
*
//
* @author duanledexianxianxian
// /**
*/
// * 用户表单对象.
@Data
// *
public
static
class
UserForm
implements
Serializable
{
// * @author duanledexianxianxian
// */
private
static
final
long
serialVersionUID
=
5681371348688016281L
;
// @Data
/**
// public static class UserForm implements Serializable {
* 用户名
//
*/
// private static final long serialVersionUID = 5681371348688016281L;
private
String
userName
;
// /**
/**
// * 用户名
* 地址
// */
*/
// private String userName;
private
String
address
;
// /**
/**
// * 地址
* 年龄
// */
*/
// private String address;
private
Integer
age
;
// /**
}
// * 年龄
// */
/**
// private Integer age;
* 添加用户
// }
*
//
* @param form 用户表单对象
// /**
* @return integer 返回记录
// * 添加用户
*/
// *
@PostMapping
// * @param form 用户表单对象
public
Integer
add
(
@RequestBody
UserForm
form
)
{
// * @return integer 返回记录
return
null
;
// */
}
// @PostMapping
// public Integer add(@RequestBody UserForm form) {
// return null;
// }
}
}
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