Commit 678ef8b4 authored by duanledexianxianxian's avatar duanledexianxianxian 😁

代码重构

parent 8e6f9c27
package com.github.fengyuchenglun.apidoc.core;
import com.github.fengyuchenglun.apidoc.core.common.Constants;
import com.github.fengyuchenglun.apidoc.core.common.enums.FieldShowWay;
import com.github.fengyuchenglun.apidoc.core.render.AsciiDocRender;
import com.github.fengyuchenglun.apidoc.core.render.PostmanRender;
import com.google.common.collect.Lists;
......@@ -44,7 +45,6 @@ public class Context {
public static final String DEFAULT_CODE_STRUCTURE = "src/main/java";
/**
* 设置当前解析框架
*/
......@@ -115,6 +115,14 @@ public class Context {
@Setter
private String markdownTemplate = Constants.MARKDOWN_TEMPLATE;
/**
* 字段显示方式.
* 1. 平级(默认)
* 2. tree
*/
@Setter
private FieldShowWay fileShowWay= FieldShowWay.FLAT;
/**
* 自定义扩展参数
*/
......
......@@ -2,18 +2,43 @@ package com.github.fengyuchenglun.apidoc.core.common;
import com.google.common.base.Strings;
/**
* The type Assert.
*
* @author duanledexianxianxian
*/
public class Assert {
/**
* Is blank boolean.
*
* @param text the text
* @return the boolean
*/
public static boolean isBlank(String text) {
return Strings.isNullOrEmpty(text) || Strings.isNullOrEmpty(text.trim());
}
/**
* Not blank.
*
* @param text the text
* @param message the message
*/
public static void notBlank(String text, String message) {
if (Strings.isNullOrEmpty(text) || Strings.isNullOrEmpty(text.trim())) {
throw new IllegalArgumentException(message);
}
}
/**
* Between.
*
* @param num the num
* @param min the min
* @param max the max
* @param message the message
*/
public static void between(int num, int min, int max, String message) {
if (num < min || num > max) {
throw new IllegalArgumentException(message);
......
......@@ -31,5 +31,18 @@ public class Constants {
* 自定义tag-mock
*/
public static final String TAG_CUSTOM_JAVA_DOC_MOCK = "mock";
/**
* 自定义tag-data
*/
public static final String TAG_CUSTOM_JAVA_DOC_DATA = "data";
/**
* javadoc-tag-return
*/
public static final String TAG_JAVA_DOC_RETURN = "return";
/**
* 空格符
*/
public static final String FIELD_SPACE = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}
......@@ -7,8 +7,16 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.Iterator;
/**
* The type Object mappers.
*
* @author duanledexianxianxian
*/
public class ObjectMappers {
/**
* The constant instance.
*/
public static final ObjectMapper instance;
static {
......@@ -16,6 +24,12 @@ public class ObjectMappers {
instance.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
/**
* Pretty string.
*
* @param node the node
* @return the string
*/
public static String pretty(Object node) {
try {
return instance.writerWithDefaultPrettyPrinter().writeValueAsString(node);
......@@ -24,6 +38,13 @@ public class ObjectMappers {
}
}
/**
* Merge object node.
*
* @param result the result
* @param nodes the nodes
* @return the object node
*/
public static ObjectNode merge(ObjectNode result, ObjectNode... nodes) {
if (result != null) {
for (ObjectNode node : nodes) {
......
......@@ -7,10 +7,25 @@ import org.apache.commons.lang3.ObjectUtils;
import java.util.Iterator;
/**
* The type Query string builder.
*
* @author duanledexianxianxian
*/
public class QueryStringBuilder {
/**
* The Builder.
*/
private StringBuilder builder = new StringBuilder();
/**
* Append query string builder.
*
* @param key the key
* @param value the value
* @return the query string builder
*/
public QueryStringBuilder append(Object key, Object value) {
if (builder.length() > 0) {
builder.append("&");
......@@ -21,6 +36,12 @@ public class QueryStringBuilder {
return this;
}
/**
* Append query string builder.
*
* @param objectNode the object node
* @return the query string builder
*/
public QueryStringBuilder append(ObjectNode objectNode) {
Iterator<String> iterator = objectNode.fieldNames();
while (iterator.hasNext()) {
......
......@@ -9,25 +9,56 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* The type Uri.
*
* @author duanledexianxianxian
*/
@Getter
@EqualsAndHashCode
public class URI {
/**
* The Text.
*/
private String text;
/**
* The Next.
*/
private URI next;
/**
* Instantiates a new Uri.
*/
public URI() {
}
/**
* Instantiates a new Uri.
*
* @param text the text
*/
public URI(String text) {
this.text = text;
}
/**
* Add uri.
*
* @param text the text
* @return the uri
*/
public URI add(String text) {
return add(new URI(text));
}
/**
* Add uri.
*
* @param uri the uri
* @return the uri
*/
public URI add(URI uri) {
if (next != null) {
next.add(uri);
......@@ -37,6 +68,11 @@ public class URI {
return this;
}
/**
* Remove.
*
* @param uri the uri
*/
public void remove(URI uri) {
if (Objects.equals(next, uri)) {
next = null;
......@@ -59,6 +95,11 @@ public class URI {
return builder.toString();
}
/**
* Append to.
*
* @param list the list
*/
private void appendTo(List<String> list) {
if (Objects.nonNull(text)) {
list.addAll(Lists.newArrayList(text.split("/")));
......
......@@ -2,71 +2,65 @@ package com.github.fengyuchenglun.apidoc.core.common.convert;
import com.google.common.collect.Maps;
import java.sql.JDBCType;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
/**
* The enum Field type convert.
* 字段转换.
*
* @author duanledexianxianxian
*/
public enum FieldTypeConvert implements IFieldTypeConvert {
/**
* String field type convert.
* String.
*/
STRING("String", "String"),
/**
* Byte field type convert.
* Byte.
*/
BYTE("Byte", "Byte"),
/**
* Short field type convert.
* Short.
*/
SHORT("Integer", "Short"),
/**
* Char field type convert.
* Char.
*/
CHAR("String", "Char"),
/**
* Int field type convert.
* Int.
*/
INT("Integer", "int"),
/**
* Long field type convert.
* Long.
*/
LONG("Long", "Long"),
/**
* Boolean field type convert.
* Boolean.
*/
BOOLEAN("Boolean", "Boolean"),
/**
* Float field type convert.
* Float.
*/
FLOAT("Float", "Float"),
/**
* Double field type convert.
* Double.
*/
DOUBLE("Double", "Double"),
/**
* Local date field type convert.
* Local date.
*/
LOCAL_DATE("Date", "LocalDate"),
/**
* Local date time field type convert.
* Local date time.
*/
LOCAL_DATE_TIME("DateTime", "LocalDateTime"),
/**
* Local time field type convert.
* Local time.
*/
LOCAL_TIME("Time", "LocalTime"),
/**
* Other field type convert.
* Other.
*/
OTHER("object", "Object"),
;
......
......@@ -105,7 +105,7 @@ public class ArrayTypeDescription extends TypeDescription {
@Override
public String fullKey() {
return StringHelper.join("[].", prefix, key);
return StringHelper.join(".", prefix, key);
}
@Override
......
package com.github.fengyuchenglun.apidoc.core.common.description;
import com.github.fengyuchenglun.apidoc.core.common.ObjectMappers;
import com.github.fengyuchenglun.apidoc.core.common.helper.StringHelper;
import com.github.fengyuchenglun.apidoc.core.schema.Row;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Lists;
......@@ -121,6 +122,11 @@ public class ObjectTypeDescription extends TypeDescription {
}
}
@Override
public String fullKey() {
return StringHelper.join(".", prefix, key);
}
@Override
public ObjectNode getValue() {
return value;
......
......@@ -5,6 +5,7 @@ import lombok.EqualsAndHashCode;
/**
* 字符串类型
* @author duanledexianxianxian
*/
@EqualsAndHashCode(callSuper = true)
@Data
......
......@@ -20,6 +20,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import static com.github.fengyuchenglun.apidoc.core.common.Constants.TAG_CUSTOM_JAVA_DOC_DATA;
import static com.github.fengyuchenglun.apidoc.core.common.Constants.TAG_CUSTOM_JAVA_DOC_MOCK;
/**
......@@ -78,6 +79,12 @@ public abstract class TypeDescription {
*/
protected Boolean required = false;
/**
* The Level.
*/
protected Integer level = 0;
/**
* Is available boolean.
*
......@@ -180,7 +187,7 @@ public abstract class TypeDescription {
if (remark == null) {
remark = value;
} else {
remark += " " + value;
remark = StringUtils.isNotBlank(remark) ? remark : value;
}
}
......@@ -206,9 +213,9 @@ public abstract class TypeDescription {
return Lists.newArrayList();
}
String def;
if (null != tags.get(TAG_CUSTOM_JAVA_DOC_MOCK)) {
def = tags.get(TAG_CUSTOM_JAVA_DOC_MOCK).getContent();
} else if (defaultValue != null) {
if (defaultValue != null) {
def = String.valueOf(defaultValue);
} else if (value != null) {
def = String.valueOf(value);
......@@ -216,11 +223,20 @@ public abstract class TypeDescription {
def = "";
}
String mock = def;
if (null != tags.get(TAG_CUSTOM_JAVA_DOC_MOCK)) {
mock = tags.get(TAG_CUSTOM_JAVA_DOC_MOCK).getContent();
}
Boolean isData = false;
if (null != tags.get(TAG_CUSTOM_JAVA_DOC_DATA)) {
isData = true;
}
// if (required != null) {
// condition.append("required=").append(required);
// }
return Lists.newArrayList(new Row(fullKey, type, required, condition.toString(), def, remark, parameterType));
return Lists.newArrayList(new Row(fullKey, type, required, condition.toString(), def, remark, mock, parameterType, isData));
}
......
......@@ -15,6 +15,7 @@ import java.util.List;
/**
* 文件对比工具
* @author duanledexianxianxian
*/
@Getter
public class FileMatcher {
......
......@@ -6,6 +6,9 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
/**
* @author duanledexianxianxian
*/
public class FileSystem {
public static boolean open(Path path) {
......
package com.github.fengyuchenglun.apidoc.core.common.enums;
/**
* 字段显示方式
*
* @author duanledexianxianxian
*/
public enum FieldShowWay {
/**
* 平级方式.
*/
FLAT,
/**
* 树级目录.
*/
TREE
}
......@@ -7,6 +7,9 @@ import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* @author duanledexianxianxian
*/
public class AnnotationHelper {
public static boolean isAnnotationPresent(NodeWithAnnotations node, List<String> annotationNames) {
......
......@@ -9,6 +9,9 @@ import lombok.extern.slf4j.Slf4j;
import java.util.Optional;
/**
* @author duanledexianxianxian
*/
@Slf4j
public class ClassDeclarationHelper {
......
......@@ -17,6 +17,7 @@ import java.util.stream.Collectors;
/**
* The type Comment helper.
* @author duanledexianxianxian
*/
public class CommentHelper {
......
......@@ -5,8 +5,18 @@ import com.github.javaparser.ast.Node;
import java.util.Optional;
/**
* The type Compilation unit helper.
* @author duanledexianxianxian
*/
public class CompilationUnitHelper {
/**
* Gets compilation unit.
*
* @param node the node
* @return the compilation unit
*/
public static Optional<CompilationUnit> getCompilationUnit(Node node) {
if (node instanceof CompilationUnit) {
return Optional.of((CompilationUnit) node);
......
......@@ -14,6 +14,7 @@ import java.util.Optional;
/**
* The type Field helper.
* @author duanledexianxianxian
*/
public class FieldHelper {
......
......@@ -11,9 +11,19 @@ import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;
/**
* The type File helper.
* @author duanledexianxianxian
*/
@Slf4j
public class FileHelper {
/**
* Write.
*
* @param file the file
* @param content the content
*/
public static void write(Path file, String content) {
if (file.getParent() != null) {
......@@ -32,6 +42,13 @@ public class FileHelper {
}
}
/**
* Find list.
*
* @param start the start
* @param structure the structure
* @return the list
*/
public static List<Path> find(Path start, String structure) {
try {
return Files.walk(start)
......
......@@ -8,12 +8,32 @@ import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParse
import java.util.Optional;
/**
* The type Json property helper.
*
* @author duanledexianxianxian
*/
public class JsonPropertyHelper {
/**
* The constant ANNOTAION_JSON_PROPERTY.
*/
public static final String ANNOTAION_JSON_PROPERTY = "JsonProperty";
/**
* The constant ANNOTAION_JSON_FIELD.
*/
public static final String ANNOTAION_JSON_FIELD = "JSONField";
/**
* The constant ANNOTAION_SERIALIZED_NAME.
*/
public static final String ANNOTAION_SERIALIZED_NAME = "SerializedName";
/**
* Get json name optional.
*
* @param declaredField the declared field
* @return the optional
*/
public static Optional<String> getJsonName(ResolvedFieldDeclaration declaredField){
if(declaredField instanceof JavaParserFieldDeclaration){
FieldDeclaration fieldDeclaration = ((JavaParserFieldDeclaration) declaredField).getWrappedNode();
......@@ -26,6 +46,14 @@ public class JsonPropertyHelper {
return Optional.empty();
}
/**
* Get string value optional.
*
* @param fieldDeclaration the field declaration
* @param anno the anno
* @param attr the attr
* @return the optional
*/
public static Optional<String> getStringValue(FieldDeclaration fieldDeclaration, String anno, String attr){
Optional<AnnotationExpr> optional = fieldDeclaration.getAnnotationByName(anno);
if (optional.isPresent()) {
......
......@@ -6,6 +6,7 @@ import java.util.Set;
/**
* 解决循环依赖问题
* @author duanledexianxianxian
*/
public class ReferenceContext {
......
......@@ -2,6 +2,9 @@ package com.github.fengyuchenglun.apidoc.core.common.helper;
import com.google.common.base.Strings;
/**
* @author duanledexianxianxian
*/
public class StringHelper {
public static boolean isBlank(String text) {
......
......@@ -6,8 +6,18 @@ import com.github.javaparser.ast.type.Type;
import java.util.Optional;
/**
* The type Type name helper.
* @author duanledexianxianxian
*/
public class TypeNameHelper {
/**
* Get name string.
*
* @param type the type
* @return the string
*/
public static String getName(Type type){
String name = type.toString();
if(type.isClassOrInterfaceType()){
......@@ -21,6 +31,13 @@ public class TypeNameHelper {
return name;
}
/**
* Get name from import string.
*
* @param name the name
* @param compilationUnit the compilation unit
* @return the string
*/
private static String getNameFromImport(String name, CompilationUnit compilationUnit){
int dotPos = name.indexOf('.');
String prefix = null;
......
......@@ -9,6 +9,9 @@ import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* @author duanledexianxianxian
*/
public class TypeParameterHelper {
/**
......
package com.github.fengyuchenglun.apidoc.core.common.markup.asciidoc;
/**
* The enum Ascii doc.
* @author duanledexianxianxian
*/
public enum AsciiDoc implements CharSequence {
/**
* Extension ascii doc.
*/
EXTENSION(".adoc"),
/**
* 各种关键字
*/
HEADER("= "),
/**
* Table ascii doc.
*/
TABLE("|==="),
/**
* Table cell ascii doc.
*/
TABLE_CELL("|"),
/**
* Title ascii doc.
*/
TITLE("="),
/**
* Emphasized ascii doc.
*/
EMPHASIZED("_"),
/**
* Strong ascii doc.
*/
STRONG("*"),
/**
* Monospaced ascii doc.
*/
MONOSPACED("+"),
/**
* Quoted ascii doc.
*/
QUOTED("`"),
/**
* Double quoted ascii doc.
*/
DOUBLE_QUOTED("``"),
/**
* Unquoted ascii doc.
*/
UNQUOTED("#"),
/**
* List flag ascii doc.
*/
LIST_FLAG("1. "),
/**
* List flag letter ascii doc.
*/
LIST_FLAG_LETTER("a. "),
/**
* List flag letter upper ascii doc.
*/
LIST_FLAG_LETTER_UPPER("A. "),
/**
* Listing ascii doc.
*/
LISTING("----"),
/**
* Literal ascii doc.
*/
LITERAL("...."),
/**
* Sidebar ascii doc.
*/
SIDEBAR("****"),
/**
* Comment ascii doc.
*/
COMMENT("////"),
/**
* Passthrough ascii doc.
*/
PASSTHROUGH("++++"),
/**
* Quote ascii doc.
*/
QUOTE("____"),
/**
* Example ascii doc.
*/
EXAMPLE("===="),
/**
* Note ascii doc.
*/
NOTE("NOTE"),
/**
* Tip ascii doc.
*/
TIP("TIP"),
/**
* Important ascii doc.
*/
IMPORTANT("IMPORTANT"),
/**
* Warning ascii doc.
*/
WARNING("WARNING"),
/**
* Caution ascii doc.
*/
CAUTION("CAUTION"),
/**
* Pagebreaks ascii doc.
*/
PAGEBREAKS("<<<"),
/**
* Hardbreaks ascii doc.
*/
HARDBREAKS("[%hardbreaks]"),
/**
* Whitespace ascii doc.
*/
WHITESPACE(" "),
/**
* Br ascii doc.
*/
BR("\r\n"),
/**
* New line ascii doc.
*/
NEW_LINE("\r\n\r\n"),
/**
* Hbr ascii doc.
*/
HBR(" +"),
/**
* 文档属性
*/
TOC(":toc:"),
/**
* Left ascii doc.
*/
LEFT("left"),
/**
* Toc level ascii doc.
*/
TOC_LEVEL(":toclevels:"),
/**
* Toc title ascii doc.
*/
TOC_TITLE(":toc-title:"),
/**
* Doctype ascii doc.
*/
DOCTYPE(":doctype:"),
/**
* Book ascii doc.
*/
BOOK("book"),
/**
* Source highlighter ascii doc.
*/
SOURCE_HIGHLIGHTER(":source-highlighter:"),
/**
* Prettify ascii doc.
*/
PRETTIFY("prettify"),
/**
* Highlightjs ascii doc.
*/
HIGHLIGHTJS("highlightjs"),
/**
* Coderay ascii doc.
*/
CODERAY("coderay"),
/**
* 文字样式
*/
STYLE_BIG("big"),
/**
* Style small ascii doc.
*/
STYLE_SMALL("small"),
/**
* Style underline ascii doc.
*/
STYLE_UNDERLINE("underline"),
/**
* Style overline ascii doc.
*/
STYLE_OVERLINE("overline"),
/**
* Style line through ascii doc.
*/
STYLE_LINE_THROUGH("line-through"),
;
/**
* The Markup.
*/
private final String markup;
/**
* Instantiates a new Ascii doc.
*
* @param markup the markup
*/
AsciiDoc(final String markup) {
this.markup = markup;
}
......@@ -85,6 +229,13 @@ public enum AsciiDoc implements CharSequence {
return markup;
}
/**
* Attr char sequence.
*
* @param key the key
* @param value the value
* @return the char sequence
*/
public static CharSequence attr(AsciiDoc key, Object value){
return key.toString() + " " + String.valueOf(value);
}
......
......@@ -9,10 +9,21 @@ import java.util.Objects;
import java.util.function.Consumer;
import java.util.regex.Matcher;
/**
* The type Ascii doc builder.
*
* @author duanledexianxianxian
*/
public class AsciiDocBuilder implements MarkupBuilder {
/**
* The constant MAX_TITLE.
*/
public static final int MAX_TITLE = 6;
/**
* The Content.
*/
private StringBuilder content = new StringBuilder();
@Override
......@@ -241,6 +252,14 @@ public class AsciiDocBuilder implements MarkupBuilder {
}
/**
* Style markup builder.
*
* @param flag the flag
* @param text the text
* @param textStyle the text style
* @return the markup builder
*/
public MarkupBuilder style(CharSequence flag, String text, CharSequence... textStyle) {
if (Assert.isBlank(text)) {
return this;
......@@ -324,6 +343,12 @@ public class AsciiDocBuilder implements MarkupBuilder {
content = new StringBuilder();
}
/**
* Nobr string.
*
* @param content the content
* @return the string
*/
String nobr(String content) {
if (Assert.isBlank(content)) {
return content;
......
......@@ -2,6 +2,7 @@ package com.github.fengyuchenglun.apidoc.core.common.markup.asciidoc;
/**
* https://en.wikipedia.org/wiki/Web_colors#HTML_color_names
* @author duanledexianxianxian
*/
public enum Color implements CharSequence{
WHITE("white"),
......
package com.github.fengyuchenglun.apidoc.core.common.markup.markdown;
public enum Markdown implements CharSequence {
EXTENSION(".md"),
/**
* 各种关键字
*/
HEADER("# "),
TABLE_CELL("|"),
TABLE_ROW("-"),
TABLE_Header("---|"),
TITLE("#"),
EMPHASIZED("**"),
STRONG("**"),
MONOSPACED("`"),
QUOTED("**"),
DOUBLE_QUOTED("**"),
UNQUOTED("**"),
LIST_FLAG("* "),
LISTING("```"),
LITERAL("```"),
SIDEBAR("```"),
COMMENT("```"),
PASSTHROUGH("```"),
QUOTE("> "),
EXAMPLE("===="),
NOTE("NOTE"),
TIP("TIP"),
IMPORTANT("IMPORTANT"),
WARNING("WARNING"),
CAUTION("CAUTION"),
PAGEBREAKS(" "),
WHITESPACE(" "),
BR("\r\n"),
NEW_LINE("\r\n\r\n"),
HBR(" +"),
;
private final String markup;
Markdown(final String markup) {
this.markup = markup;
}
@Override
public int length() {
return markup.length();
}
@Override
public char charAt(int index) {
return markup.charAt(index);
}
@Override
public CharSequence subSequence(int start, int end) {
return markup.subSequence(start, end);
}
@Override
public String toString() {
return markup;
}
public static CharSequence attr(Markdown key, Object value){
return key.toString() + " " + String.valueOf(value);
}
}
package com.github.fengyuchenglun.apidoc.core.common.markup.markdown;
import com.github.fengyuchenglun.apidoc.core.common.Assert;
import com.github.fengyuchenglun.apidoc.core.common.markup.MarkupBuilder;
import com.google.common.base.Strings;
import java.util.List;
import java.util.function.Consumer;
import java.util.regex.Matcher;
public class MarkdownBuilder implements MarkupBuilder {
public static final int MAX_TITLE = 6;
private StringBuilder content = new StringBuilder();
@Override
public MarkupBuilder header(String text, CharSequence... attrs) {
Assert.notBlank(text, "header must not be blank");
content.append(Markdown.HEADER);
content.append(nobr(text.trim()));
br();
return this;
}
@Override
public MarkupBuilder title(int level, String text) {
Assert.notBlank(text, "header must not be blank");
Assert.between(level, 1, MAX_TITLE, "title level can not be " + level);
br();
content.append(Strings.repeat(Markdown.TITLE.toString(), level + 1)).append(Markdown.WHITESPACE)
.append(nobr(text.trim()));
br();
return this;
}
@Override
public MarkupBuilder text(String text) {
if (Assert.isBlank(text)) {
return this;
}
content.append(text.trim());
return this;
}
@Override
public MarkupBuilder textLine(String text) {
if (Assert.isBlank(text)) {
return this;
}
text(nobr(text));
br();
return this;
}
@Override
public MarkupBuilder paragraph(String text, CharSequence... attrs) {
if (Assert.isBlank(text)) {
return this;
}
text(text);
newLine();
return this;
}
@Override
public MarkupBuilder note(String text) {
content.append(Markdown.QUOTE);
paragraph(text);
return this;
}
@Override
public MarkupBuilder tip(String text) {
content.append(Markdown.QUOTE);
paragraph(text);
return this;
}
@Override
public MarkupBuilder important(String text) {
content.append(Markdown.QUOTE);
paragraph(text);
return this;
}
@Override
public MarkupBuilder warning(String text) {
content.append(Markdown.QUOTE);
paragraph(text);
return this;
}
@Override
public MarkupBuilder caution(String text) {
content.append(Markdown.QUOTE);
paragraph(text);
return this;
}
@Override
public MarkupBuilder block(Consumer<MarkupBuilder> consumer, CharSequence flag, CharSequence... attrs) {
content.append(flag);
br();
consumer.accept(this);
br();
content.append(flag);
newLine();
return this;
}
@Override
public MarkupBuilder listing(Consumer<MarkupBuilder> consumer, CharSequence... attrs) {
return block(consumer, Markdown.LISTING, attrs);
}
@Override
public MarkupBuilder literal(Consumer<MarkupBuilder> consumer, CharSequence... attrs) {
return block(consumer, Markdown.LISTING, attrs);
}
@Override
public MarkupBuilder sidebar(Consumer<MarkupBuilder> consumer, CharSequence... attrs) {
return block(consumer, Markdown.LISTING, attrs);
}
@Override
public MarkupBuilder comment(Consumer<MarkupBuilder> consumer, CharSequence... attrs) {
return block(consumer, Markdown.LISTING, attrs);
}
@Override
public MarkupBuilder passthrough(Consumer<MarkupBuilder> consumer, CharSequence... attrs) {
return block(consumer, Markdown.LISTING, attrs);
}
@Override
public MarkupBuilder quote(Consumer<MarkupBuilder> consumer, CharSequence... attrs) {
return block(consumer, Markdown.LISTING, attrs);
}
@Override
public MarkupBuilder example(Consumer<MarkupBuilder> consumer, CharSequence... attrs) {
return block(consumer, Markdown.LISTING, attrs);
}
@Override
public MarkupBuilder list(String text) {
return list(text, Markdown.LIST_FLAG);
}
@Override
public MarkupBuilder list(String text, CharSequence flag) {
if (!Assert.isBlank(text)) {
content.append(flag).append(nobr(text));
}
return this;
}
@Override
public MarkupBuilder url(String text, String url) {
if (!Assert.isBlank(text) && !Assert.isBlank(url)) {
content.append("[").append(nobr(text)).append("](").append(url).append(")");
br();
}
return this;
}
@Override
public MarkupBuilder image(String text, String url) {
if (!Assert.isBlank(text) && !Assert.isBlank(url)) {
text("!");
url(text, url);
}
return this;
}
@Override
public MarkupBuilder table(List<List<String>> data) {
return table(data, true, false);
}
@Override
public MarkupBuilder table(List<List<String>> data, boolean header, boolean footer) {
for (int i = 0; i < data.size(); i++) {
content.append(Markdown.TABLE_CELL);
for (int j = 0; j < data.get(i).size(); j++) {
String value = data.get(i).get(j);
if(value!=null){
content.append(data.get(i).get(j).replace(Markdown.TABLE_CELL, "\\" + Markdown.TABLE_CELL));
}else{
content.append(" ");
}
content.append(Markdown.TABLE_CELL);
}
br();
if(i==0 && header){
content.append(Markdown.TABLE_CELL);
for (int j = 0; j < data.get(i).size(); j++) {
content.append(Markdown.TABLE_Header);
}
br();
}
if(i==data.size()-2 && footer){
content.append(Markdown.TABLE_CELL);
for (int j = 0; j < data.get(i).size(); j++) {
content.append(Markdown.TABLE_Header);
}
br();
}
}
newLine();
return this;
}
public MarkupBuilder style(CharSequence flag, String text, CharSequence... textStyle) {
if (Assert.isBlank(text)) {
return this;
}
content.append(flag);
text(text);
content.append(flag);
return this;
}
@Override
public MarkupBuilder emphasized(String text, CharSequence... textStyle) {
return style(Markdown.EMPHASIZED, text, textStyle);
}
@Override
public MarkupBuilder strong(String text, CharSequence... textStyle) {
return style(Markdown.STRONG, text, textStyle);
}
@Override
public MarkupBuilder monospaced(String text, CharSequence... textStyle) {
return style(Markdown.MONOSPACED, text, textStyle);
}
@Override
public MarkupBuilder quoted(String text, CharSequence... textStyle) {
return style(Markdown.QUOTE, text, textStyle);
}
@Override
public MarkupBuilder doubleQuoted(String text, CharSequence... textStyle) {
return style(Markdown.DOUBLE_QUOTED, text, textStyle);
}
@Override
public MarkupBuilder unquoted(String text, CharSequence... textStyle) {
return style(Markdown.UNQUOTED, text, textStyle);
}
@Override
public MarkupBuilder br() {
content.append(Markdown.BR);
return this;
}
@Override
public MarkupBuilder hbr() {
content.append(Markdown.HBR);
return this;
}
@Override
public MarkupBuilder newLine() {
content.append(Markdown.NEW_LINE);
return this;
}
@Override
public MarkupBuilder pageBreak() {
content.append(Markdown.PAGEBREAKS);
br();
return this;
}
@Override
public String getContent() {
return content.toString();
}
@Override
public void clean() {
content = new StringBuilder();
}
String nobr(String content) {
if (Assert.isBlank(content)) {
return content;
}
return content.replaceAll(Markdown.BR.toString(),
Matcher.quoteReplacement(Markdown.WHITESPACE.toString()));
}
}
......@@ -10,6 +10,11 @@ import com.google.common.collect.ImmutableList;
import java.util.Optional;
/**
* The type Collection type resolver.
*
* @author duanledexianxianxian
*/
public class CollectionTypeResolver implements TypeResolver {
@Override
public boolean accept(ResolvedType type) {
......@@ -24,6 +29,12 @@ public class CollectionTypeResolver implements TypeResolver {
.orElseGet(UnAvailableTypeDescription::new));
}
/**
* Is collection boolean.
*
* @param type the type
* @return the boolean
*/
private static boolean isCollection(ResolvedType type){
if(!type.isReferenceType()){
return false;
......@@ -31,6 +42,12 @@ public class CollectionTypeResolver implements TypeResolver {
return isCollection(type.asReferenceType().getId());
}
/**
* Is collection boolean.
*
* @param id the id
* @return the boolean
*/
private static boolean isCollection(String id){
return ImmutableList.of("java.util.List",
"java.util.Collection",
......
......@@ -5,6 +5,11 @@ import com.github.fengyuchenglun.apidoc.core.common.description.StringTypeDescri
import com.github.javaparser.resolution.types.ResolvedType;
import com.google.common.collect.ImmutableList;
/**
* The type Date type resolver.
*
* @author duanledexianxianxian
*/
public class DateTypeResolver implements TypeResolver {
@Override
public boolean accept(ResolvedType type) {
......@@ -16,6 +21,12 @@ public class DateTypeResolver implements TypeResolver {
return new StringTypeDescription(type.asReferenceType().getTypeDeclaration().getName(),"");
}
/**
* Is date boolean.
*
* @param type the type
* @return the boolean
*/
private static boolean isDate(ResolvedType type){
if(!type.isReferenceType()){
return false;
......@@ -23,6 +34,12 @@ public class DateTypeResolver implements TypeResolver {
return isDate(type.asReferenceType().getId());
}
/**
* Is date boolean.
*
* @param id the id
* @return the boolean
*/
private static boolean isDate(String id){
return ImmutableList.of("java.util.Date",
"java.time.LocalDateTime",
......
......@@ -6,6 +6,11 @@ import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclara
import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration;
import com.github.javaparser.resolution.types.ResolvedType;
/**
* The type Enum type resolver.
*
* @author duanledexianxianxian
*/
public class EnumTypeResolver implements TypeResolver {
@Override
public boolean accept(ResolvedType type) {
......
......@@ -7,8 +7,16 @@ import com.google.common.collect.ImmutableList;
/**
* 不支持直接使用Map,建议使用DTO
*
* @author duanledexianxianxian
*/
public class MapTypeResolver implements TypeResolver {
/**
* Is map boolean.
*
* @param type the type
* @return the boolean
*/
private static boolean isMap(ResolvedType type) {
if (!type.isReferenceType()) {
return false;
......@@ -16,6 +24,12 @@ public class MapTypeResolver implements TypeResolver {
return isMap(type.asReferenceType().getId());
}
/**
* Is map boolean.
*
* @param id the id
* @return the boolean
*/
private static boolean isMap(String id) {
return ImmutableList.of("java.util.Map",
"java.util.HashMap",
......
......@@ -17,6 +17,8 @@ import java.util.Optional;
/**
* java bean解析
*
* @author duanledexianxianxian
*/
public class ObjectTypeResolver implements TypeResolver {
......@@ -88,6 +90,12 @@ public class ObjectTypeResolver implements TypeResolver {
}
/**
* Sets default.
*
* @param declaredField the declared field
* @param fieldDescription the field description
*/
private void setDefault(ResolvedFieldDeclaration declaredField, TypeDescription fieldDescription) {
Optional<Comment> optional = CommentHelper.getOptionalComment(declaredField);
if (optional.isPresent()) {
......
......@@ -5,6 +5,11 @@ import com.github.fengyuchenglun.apidoc.core.common.description.StringTypeDescri
import com.github.javaparser.resolution.types.ResolvedType;
import com.google.common.collect.ImmutableList;
/**
* The type String type resolver.
*
* @author duanledexianxianxian
*/
public class StringTypeResolver implements TypeResolver {
@Override
public boolean accept(ResolvedType type) {
......@@ -16,6 +21,12 @@ public class StringTypeResolver implements TypeResolver {
return new StringTypeDescription("String","");
}
/**
* Is string boolean.
*
* @param type the type
* @return the boolean
*/
private static boolean isString(ResolvedType type){
if(!type.isReferenceType()){
return false;
......@@ -23,6 +34,12 @@ public class StringTypeResolver implements TypeResolver {
return isString(type.asReferenceType().getId());
}
/**
* Is string boolean.
*
* @param id the id
* @return the boolean
*/
private static boolean isString(String id){
return ImmutableList.of("java.lang.String",
"java.lang.CharSequence"
......
......@@ -4,6 +4,11 @@ import com.github.fengyuchenglun.apidoc.core.common.description.TypeDescription;
import com.github.fengyuchenglun.apidoc.core.common.description.UnAvailableTypeDescription;
import com.github.javaparser.resolution.types.ResolvedType;
/**
* The type System object type resolver.
*
* @author duanledexianxianxian
*/
public class SystemObjectTypeResolver implements TypeResolver {
@Override
public boolean accept(ResolvedType type) {
......@@ -15,6 +20,12 @@ public class SystemObjectTypeResolver implements TypeResolver {
return new UnAvailableTypeDescription();
}
/**
* Is system boolean.
*
* @param type the type
* @return the boolean
*/
private static boolean isSystem(ResolvedType type){
if(!type.isReferenceType()){
return false;
......@@ -22,6 +33,12 @@ public class SystemObjectTypeResolver implements TypeResolver {
return isSystem(type.asReferenceType().getId());
}
/**
* Is system boolean.
*
* @param id the id
* @return the boolean
*/
private static boolean isSystem(String id){
return id!=null && (id.startsWith("java") ||id.startsWith("sun"));
}
......
package com.github.fengyuchenglun.apidoc.core.schema;
import com.github.fengyuchenglun.apidoc.core.ApiDoc;
import com.github.fengyuchenglun.apidoc.core.common.convert.FieldTypeConvert;
import com.github.fengyuchenglun.apidoc.core.common.convert.IFieldTypeConvert;
import com.github.fengyuchenglun.apidoc.core.common.enums.FieldShowWay;
import lombok.*;
import org.apache.commons.lang3.StringUtils;
import static com.github.fengyuchenglun.apidoc.core.common.Constants.FIELD_SPACE;
/**
* The type Row.
*
......@@ -41,12 +45,21 @@ public class Row {
* 说明.
*/
String remark;
/**
* mock值
*/
String mock;
/**
* 请求参数类型
*/
String parameterType;
/**
* 是否为统一结果
*/
Boolean isData;
/**
* Instantiates a new Row.
......@@ -75,17 +88,41 @@ public class Row {
* @return the label type
*/
public String getLabelType() {
String javaType=this.type;
Boolean isArray=false;
if (StringUtils.endsWith(javaType,"[]")){
javaType=StringUtils.substringBefore(this.type,"[]");
isArray=true;
String javaType = this.type;
Boolean isArray = false;
if (StringUtils.endsWith(javaType, "[]")) {
javaType = StringUtils.substringBefore(this.type, "[]");
isArray = true;
}
IFieldTypeConvert fieldTypeConvert=FieldTypeConvert.javaTypeOf(javaType);
if (null==fieldTypeConvert){
IFieldTypeConvert fieldTypeConvert = FieldTypeConvert.javaTypeOf(javaType);
if (null == fieldTypeConvert) {
return this.type;
}
return isArray?fieldTypeConvert.getType()+"[]":fieldTypeConvert.getType();
return isArray ? fieldTypeConvert.getType() + "[]" : fieldTypeConvert.getType();
}
/**
* Gets markdown key.
*
* @return the markdown key
*/
public String getMarkdownKey() {
if (StringUtils.isNotBlank(this.key)) {
if (FieldShowWay.TREE.equals(ApiDoc.getInstance().getContext().getFileShowWay())) {
String[] keys = StringUtils.split(this.key, ".");
if (keys.length > 1) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < keys.length - 2; i++) {
sb.append(FIELD_SPACE);
}
sb.append("└─");
sb.append(keys[keys.length - 1]);
return sb.toString();
}
}
}
return this.key;
}
}
......@@ -13,6 +13,8 @@ import org.apache.commons.lang3.StringUtils;
import java.util.*;
import static com.github.fengyuchenglun.apidoc.core.common.Constants.TAG_JAVA_DOC_RETURN;
/**
* 小节,一个请求,封装为一个小节
*
......@@ -77,6 +79,10 @@ public class Section extends Node {
* The Raw response.
*/
Object rawResponse;
/**
* 是否为统一结果返回
*/
Boolean isResultData=false;
/**
* Sets parameter.
......@@ -180,7 +186,14 @@ public class Section extends Node {
* @return the query parameter string
*/
public String getQueryParameterString() {
return new QueryStringBuilder().append((ObjectNode) queryParameters).toString();
String qs = new QueryStringBuilder().append((ObjectNode) queryParameters).toString();
qs = StringUtils.replace(qs, "[\"\"]", "1,2,3");
qs = StringUtils.replace(qs, "[0]", "1,2,3");
qs = StringUtils.replace(qs, "[0.0]", "1.0,2.0,3.0");
qs = StringUtils.replace(qs, "[false]", "false,true,false");
return qs;
}
/**
......@@ -222,11 +235,15 @@ public class Section extends Node {
public void addResponseRows(Collection<Row> rows) {
for (Row row : rows) {
if (row.getKey() != null && !responseRows.containsKey(row.getKey())) {
if (row.getIsData()) {
Optional.ofNullable(this.tags.get(TAG_JAVA_DOC_RETURN)).ifPresent(x -> row.setRemark(x.content));
}
responseRows.put(row.getKey(), row);
}
}
}
/**
* Has response body boolean.
*
......
......@@ -40,18 +40,23 @@ ${section.description}
<#-- 请求示例-->
```HTTP
${section.method} ${section.uri!''} HTTP/1.1
<#if section.inHeaders??>
HTTP/1.1
<#if section.inHeaders??>
<#list section.inHeaders as inHeaderKey,inHeaderValue>
${inHeaderValue!''}
</#list>
</#if>
<#if (section.getQueryParameterString()?length gt 1)>
</#if>
${section.getQueryParameterString()}
Url:
${section.method} ${section.uri!''}
<#if (section.getQueryParameterString()?length gt 1)>
Query param:
?${section.getQueryParameterString()}
</#if>
<#if section.hasRequestBody()>
Request body:
${section.getRequestBodyParameterString()}
</#if>
```
......@@ -61,7 +66,7 @@ ${section.getRequestBodyParameterString()}
| 字段 | 类型 | 参数类型 | 必填 | 验证 | 默认值 | 描述 |
| :------- | :----- | :----- |:-------- |:-------- | :------ | :---------- |
<#list section.requestRows as rowKey,rowValue>
| ${rowValue.key!''} | ${rowValue.getLabelType()!''} | **${rowValue.parameterType!''}** |${rowValue.required?string('true','false')} | ${rowValue.condition!''} | ${rowValue.def!''} | ${rowValue.getHtmlRemark()!''} |
| ${rowValue.getMarkdownKey()!''} | ${rowValue.getLabelType()!''} | **${rowValue.parameterType!''}** |${rowValue.required?string('true','false')} | ${rowValue.condition!''} | ${rowValue.def!''} | ${rowValue.getHtmlRemark()!''} |
</#list>
</#if>
<#-- 响应-->
......@@ -74,10 +79,10 @@ ${section.getResponseString()}
<#-- 响应参数table列表-->
<#if section.responseRows?? && (section.responseRows?size>0)>
| 字段 | 类型 | 默认值 | 描述 |
| :------- | :----- |:----- | :---------- |
| 字段 | 类型 | 默认值 | 示例 | 描述 |
| :------- | :----- |:----- |:----- | :---------- |
<#list section.responseRows as rowKey,rowValue>
| ${rowValue.key!''} | ${rowValue.getLabelType()!''} | ${rowValue.def!''} | ${rowValue.getHtmlRemark()!''} |
| ${rowValue.getMarkdownKey()!''} | ${rowValue.getLabelType()!''} | ${rowValue.def!''} | ${rowValue.mock!''} | ${rowValue.getHtmlRemark()!''} |
</#list>
</#if>
</#if>
......
......@@ -5,6 +5,7 @@ import com.github.javaparser.ast.body.Parameter;
/**
* The type Parameter helper.
* @author duanledexianxianxian
*/
public class ParameterHelper {
......@@ -60,7 +61,7 @@ public class ParameterHelper {
* 是否是请求参数
*
* @param parameter the parameter
* @return boolean
* @return boolean boolean
*/
public static boolean isRequestParam(Parameter parameter) {
if (!parameter.isAnnotationPresent(ANNOTATION_PATH_VARIABLE) &&
......
package com.github.fengyuchenglun.apidoc.springmvc;
import com.github.fengyuchenglun.apidoc.core.common.description.ArrayTypeDescription;
import com.github.fengyuchenglun.apidoc.core.common.helper.AnnotationHelper;
import com.github.fengyuchenglun.apidoc.core.common.helper.ClassDeclarationHelper;
import com.github.fengyuchenglun.apidoc.core.common.helper.ExpressionHelper;
......@@ -24,6 +25,7 @@ import com.github.fengyuchenglun.apidoc.springmvc.resovler.SpringComponentTypeRe
import java.util.List;
import java.util.Optional;
import static com.github.fengyuchenglun.apidoc.core.common.Constants.TAG_JAVA_DOC_RETURN;
import static com.github.fengyuchenglun.apidoc.core.schema.ParameterType.*;
......@@ -95,6 +97,7 @@ public class SpringParser implements ParserStrategy {
/**
* 解析方法定义
*
* @param n 方法声明
* @param chapter 章
* @param section 节
......@@ -326,20 +329,36 @@ public class SpringParser implements ParserStrategy {
returnType.setTypeArguments(n.getType());
n.findCompilationUnit().get().addImport(ClassDeclarationHelper.getClassOrInterfacePackageName(resultDataClassOrInterfaceDeclaration));
n.setType(returnType);
section.setIsResultData(true);
}
TypeDescription description = ApiDoc.getInstance().getTypeResolvers().resolve(n.getType());
if (description.isAvailable()) {
if (description.isPrimitive()) {
section.setRawResponse(description.getValue());
handleResultData(section,description);
} else if (description.isString()) {
section.setRawResponse(description.getValue());
handleResultData(section,description);
} else if (description.isArray()) {
ArrayTypeDescription asArray = description.asArray();
if (asArray.getComponent().isPrimitive() || asArray.getComponent().isString()) {
handleResultData(section,description);
}
section.setResponse(description.asArray().getValue());
} else if (description.isObject()) {
section.setResponse(description.asObject().getValue());
}
section.addResponseRows(description.rows());
}
}
private void handleResultData(Section section, TypeDescription description) {
if (!section.getIsResultData()) {
description.setKey("result");
section.getTag(TAG_JAVA_DOC_RETURN).ifPresent(x -> description.setRemark(x.getContent()));
}
}
}
......@@ -51,9 +51,11 @@ public class Query {
// /**
// * 结束时间
// * 2020-07-25 01:00:00
// */
// private LocalDateTime endTime;
//
//
private LocalDateTime endTime;
private List<Menu> menuList;
private List<Query> queryList;
}
......@@ -26,6 +26,8 @@ public class ResultData<T> {
String msg;
/**
* 数据对象.
*
* @data
*/
T data;
......
......@@ -20,40 +20,32 @@ import java.util.List;
@Getter
public class User {
// /**
// * 用户编号.
// */
// int id;
// /**
// * 用户名称.
// */
// @NotBlank
// String name;
// /**
// * 用户年龄.
// */
// @Min(1)
// @NotNull
// Integer age;
// /**
// * 创建时间.
// */
// Date createAt;
// /**
// * 性别.
// */
// @NotBlank
// @JsonProperty("Sex")
// String sex;
/**
* 用户.
* 用户编号.
*/
private UserQuery query;
int id;
/**
* 用户名称.
*/
@NotBlank
String name;
/**
* 用户年龄.
* @mock 20
*/
@Min(1)
@NotNull
Integer age;
/**
* 创建时间.
* @mock 2020-07-28
*/
Date createAt;
/**
* 用户.
* 性别.
*/
private List<Menu> menus;
@NotBlank
@JsonProperty("Sex")
String sex;
}
......@@ -27,133 +27,170 @@ public class UserController {
* 查看用户详情
*
* @param userId 用户编号
* @param age 年龄
* @return the user
*/
@PostMapping(value = "/{userId}")
public User detail(@PathVariable("userId")Long userId) {
User user = new User();
return user;
}
/**
* 查看用户详情
* 测试get的query对象
*
* @param query 过滤条件
* @return 用户对象 user
*/
@PostMapping(value = "/{userId}")
public User detail(@PathVariable String userId, String age, @RequestBody Query query) {
@GetMapping(value = "/detail1")
public User detail1(Query query) {
User user = new User();
return user;
}
/**
*
* 测试返回List
*
* @param query 过滤条件
* @return 用户对象 user
*/
@GetMapping(value = "/getList")
public List<User> getList(Query query) {
return null;
}
/**
*
* 测试返回List
*
* @param query 过滤条件
* @return 用户对象 user
*/
@GetMapping(value = "/getStringList")
public List<String> getStringList(Query query) {
return null;
}
/**
*
* 测试返回List
*
* @param query 过滤条件
* @return 用户对象 user
*/
@GetMapping(value = "/getStringArrayList")
public List<List<String>> getStringArrayList(Query query) {
return null;
}
/**
* 测试get的query对象,带RequestParam注解
*
* @param query the query
* @return 用户对象 user
*/
@GetMapping(value = "/detail3")
public User detail3(Query query) {
User user = new User();
return user;
}
/**
* 测试get的query对象,带RequestParam注解,required=false
*
* @param query 过滤条件
* @return 用户对象 user
*/
@GetMapping(value = "/detail4")
public User detail4(@RequestParam(required = false) String query) {
User user = new User();
return user;
}
//
// /**
// * 查看用户详情
// * 测试get的query对象
// *
// * @param query 过滤条件
// * @return 用户对象 user
// */
// @GetMapping(value = "/detail1")
// public User detail1(Query query) {
// User user = new User();
// return user;
// }
//
//
//
// /**
// * 测试get的query对象,带RequestParam注解
// *
// * @param query the query
// * @return 用户对象 user
// */
// @GetMapping(value = "/detail3")
// public User detail3(Query query) {
// User user = new User();
// return user;
// }
//
// /**
// * 测试get的query对象,带RequestParam注解,required=false
// *
// * @param query 过滤条件
// * @return 用户对象 user
// */
// @GetMapping(value = "/detail4")
// public User detail4(@RequestParam(required = false) String query) {
// User user = new User();
// return user;
// }
//
// /**
// * get-无查询参数
// *
// * @return 用户对象 user
// */
// @GetMapping(value = "/detail5")
// public List<User> detail5() {
// return null;
// }
//
// /**
// * get-原始对象+查询对象
// *
// * @param userName the user name
// * @param age the age
// * @param query the query
// * @return 用户对象 user
// */
// @GetMapping(value = "/detail6")
// public User detail6(String userName, Integer age, UserQuery query) {
// User user = new User();
// return user;
// }
//
// /**
// * post-
// *
// * @return 用户对象 user
// */
// @GetMapping(value = "/post1")
// public UserQuery post1() {
// return null;
// }
//
//
// /**
// * 删除用户
// *
// * @param userId the user id
// * @return boolean 是否成功
// */
// @DeleteMapping(value = "/{userId}")
// public Boolean deleteUser(@PathVariable("userId") Long userId) {
// return true;
// }
//
//
// /**
// * 用户表单对象.
// *
// * @author duanledexianxianxian
// */
// @Data
// public static class UserForm implements Serializable {
//
// private static final long serialVersionUID = 5681371348688016281L;
// /**
// * 用户名
// */
// private String userName;
// /**
// * 地址
// */
// private String address;
// /**
// * 年龄
// */
// private Integer age;
// }
//
// /**
// * 添加用户
// *
// * @param form 用户表单对象
// * @return integer 返回记录
// */
// @PostMapping
// public Integer add(@RequestBody UserForm form) {
// return null;
// }
/**
* get-无查询参数
*
* @return 用户对象 user
*/
@GetMapping(value = "/detail5")
public List<User> detail5() {
return null;
}
/**
* get-原始对象+查询对象
*
* @param userName the user name
* @param age the age
* @param query the query
* @return 用户对象 user
*/
@GetMapping(value = "/detail6")
public User detail6(String userName, Integer age, UserQuery query) {
User user = new User();
return user;
}
/**
* post-
*
* @return 用户对象 user
*/
@GetMapping(value = "/post1")
public UserQuery post1() {
return null;
}
/**
* 删除用户
*
* @param userId the user id
* @return boolean 是否成功
*/
@DeleteMapping(value = "/{userId}")
public Boolean deleteUser(@PathVariable("userId") Long userId) {
return true;
}
/**
* 用户表单对象.
*
* @author duanledexianxianxian
*/
@Data
public static class UserForm implements Serializable {
/**
* The constant serialVersionUID.
*/
private static final long serialVersionUID = 5681371348688016281L;
/**
* 用户名
*/
private String userName;
/**
* 地址
*/
private String address;
/**
* 年龄
*/
private Integer age;
}
/**
* 添加用户
*
* @param form 用户表单对象
* @return 返回记录 boolean
*/
@PostMapping
public Boolean add(@RequestBody UserForm form) {
return null;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment