For front end style integration swagger, Only enhance the interface , Do not modify the interface logic , When json Style stitching complete , We put json Turn to the corresponding entity class .

front end json Style object construction reference :https://workshops.otrs365.cn/web/#/132?page_id=1248

For the front end style , This time 5 A common module class , These classes are described below

ReturnData Data returned to the front end ( Outermost layer )

ReturnData<T,L,O>

/**
* @param <T> FormStyle Inside Data The generic
* @param <L> ListHead The specific properties of the fields inside
* @param <O> OverviewList, It generally corresponds to the database table properties
* @Description:
* @author: Zhang chonghu
* @Date: 2021/6/2 9:31
* @Copyright: Xi'an Dian Tong Software Co., Ltd. All Rights Reserved.
* @Version 1.0
*/
@Data
@ApiModel
public class ReturnData<T,L,O> {
@JsonProperty("tableStyle")
@ApiModelProperty(value = " Table style ")
private Tablestyle<L,O> tablestyle;
@ApiModelProperty(value = " Form style ")
@JsonProperty("formStyle")
private Formstyle<T> formstyle;
}

ReturnData<T,L,O> Enables us to highly customize the return style

The front-end interface is simple FormStyle and TableStyle Unfold the stitching

FormStyle ( Return to the front-end form style )

FormStyle There are two basic attributes : data and order.data It's one by one order object , Inside the object are specific attributes

Formstyle<T>

@lombok.Data
@ApiModel
public class Formstyle<T> {
@ApiModelProperty(value = " Page form field specific style ")
private T data;
@ApiModelProperty(value = " Page form display fields ")
private List<String> order;
}

Data Corresponding to a generic , Generics define Data Basic properties of , Generally, the following attributes are enough , Many are inheriting this class , And then it can be expanded

FormStyleDataGeneric:

@Data
@ApiModel
public class FormStyleDataGeneric {
@JsonProperty("default")
@ApiModelProperty(value = " The default value is ")
private String defaults; @ApiModelProperty(value = " Exhibition ")
private String display; @JsonProperty("promptCode")
@ApiModelProperty(value = "0, No hint ;1, In the text box ;2, Below the field ;,3, The display icon prompts at the end of the field ;4, Displayed in red below the field ")
private int promptcode; @ApiModelProperty(value = " The form is submitted to Key")
private String name; @ApiModelProperty(value = " optional ")
private JSONObject options; @JsonProperty("disabledClear")
@ApiModelProperty(value = " Can be removed / Erasable ")
private int disabledclear; @JsonProperty("promptMessage")
@ApiModelProperty(value = " Prompt information ")
private String promptmessage; @ApiModelProperty(value = " The translation information is shown on the left Label in ")
private String label; @ApiModelProperty(value = " Field type . Text :Text, Drop down :Dropdown, Trees :SelectTree, Check box :Checkbox, Time type :DateTime( Specific date - Minutes and seconds ),Date( Specific date )")
private String type;
}

FormStyleDataGeneric The properties correspond to the front-end interface effect

Formstyle<T> ,T If FormStyleDataGeneric The attributes inside are not satisfied , You can customize one

Usage method Formstyle<FormStyleDataGeneric>

TableStyle ( Return to the front-end table style )

TableStyle<L,O>

@Data
@ApiModel
public class Tablestyle<L,O> {
@JsonProperty("PreferenceFields")
@ApiModelProperty(value = " Table header field ")
private List<String> preferencefields ; @ApiModelProperty(value = " Configurable data ")
private List<String> configData ; @ApiModelProperty(value = " The total number of table data ")
private int total; @JsonProperty("OverviewList")
@ApiModelProperty(value = " Specific data in the table ")
private List<O> overviewlist; @JsonProperty("ListHeader")
@ApiModelProperty(value = " Specific properties of header fields ")
private L listheader;
}

TableStyle<L,O> Corresponding page property description

I can see you ,TableStyle<L,O> There are two generics , If the basic attributes don't satisfy us , Let's customize a class , Then pass it in . in addition , Generic O It's usually the one corresponding to our data table dao Entity class , Just pass it in

Generic L,L representative ListHeader The properties inside , Is the property of the header field , You can't see it here on the island , We use another interface to interpret these properties .

Definition ListHeader<T> When , According to the data sheet dao To define attributes , And then add generics T that will do

ListHeader<T> , This T We usually pass on ListHeaderGeneric That's enough , If you need to add other fields , Just customize a generic , Just pass it inside

@Data
@ApiModel
public class Listheader<T> {
@ApiModelProperty(value = " Templates ")
private T template; @ApiModelProperty(value = " technological process ")
private T process; @JsonProperty("featureCode")
@ApiModelProperty(value = " Signature ")
private T featurecode; @JsonProperty("communicationConfigName")
@ApiModelProperty(value = " Mailing address name ")
private T communicationconfigname; @JsonProperty("dataPackageName")
@ApiModelProperty(value = " Packet name ")
private T datapackagename; @JsonProperty("changeBy")
@ApiModelProperty(value = " Reviser ")
private T changeby; @JsonProperty("changeTime")
@ApiModelProperty(value = " Modification time ")
private T changetime; @JsonProperty("createBy")
@ApiModelProperty(value = " The creator ")
private T createby; @JsonProperty("createTime")
@ApiModelProperty(value = " Creation time ")
private T createtime; @ApiModelProperty(value = " name ")
private T name; @JsonProperty("operationType")
@ApiModelProperty(value = " Operation type ")
private T operationtype; @ApiModelProperty(value = " remarks ")
private T comment; @ApiModelProperty(value = " explain ")
private T direction;
}

ListHeaderGeneric

@Data
@ApiModel
public class ListHeaderGeneric {
@JsonProperty("SortBy")
@ApiModelProperty(value = " Sort :0 Sortable ,1 Not sortable ")
private int sortby; @JsonProperty("Label")
@ApiModelProperty(value = " label ")
private String label; @JsonProperty("FilterKey")
@ApiModelProperty(value = " Filter key, Represents that the field can be filtered ")
private String filterkey;
}

TableStyle<L,O> Usage method TableStyle<ListHeader<ListHeaderGeneric>,Overviewlist>

A special case

The data returned is better than ReturnData more

With Communication Take the correspondence address as an example

ps: In the future, we will return to the name of the hump in capital letters , such as FormStyle instead of formStyle

Data except formStyle and tableStyle, There's an extra one myParameter

In this case , We inherit ReturnData<T, L, O> It can be expanded , If you need to explain the added attributes , Just define a generic

CommunicationTableData

@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel
public class CommunicationTableData<T, L, O> extends ReturnData<T, L, O> {
@ApiModelProperty(value = " Information about the island ( The island id, Island address )")
private JSONObject myParameter;
}

The returned data is the inner layer (Tablestyle)

Like in a packet

Look like Tablestyle, But more than Tablestyle A few more attributes , Then we can customize one ReturnData, Let it inherit directly Tablestyle, And then expand

Or not to inherit TableData, Write a ReturnData class , It contains these attributes

@Data
@ApiModel
public class TableData<L,S,O> {
@JsonProperty("PreferenceFields")
@ApiModelProperty(value = " Default display header information ")
private List<String> preferencefields ; @ApiModelProperty(value = " Search form field collection ")
private S searchFormDataOrder ; @ApiModelProperty(value = " Configurable data ")
@JsonProperty("PreferenceDisable")
private String preferenceDisable ; @ApiModelProperty(value = " The total number of table data ")
private int total; @ApiModelProperty(value = " Specific data in the table ")
@JsonProperty("OverviewList")
private List<O> Overviewlist; @JsonProperty("ListHeader")
@ApiModelProperty(value = " Header data set ")
private L listheader;
}

The returned data is the inner layer (Formstyle)

For example, the address editing interface

Looking at the structure is Formstyle, however ReturnData Both of the attributes in are Formstyle( It's usually a Formstyle And a Tablestyle), In this case , Let's just write a new one ReturnData

/**
* @param <T> BaseGenericEditData
* @param <L> CommunicationGenericEditData
* @Description:
* @author: Zhang chonghu
* @Date: 2021/6/2 15:43
* @Copyright: Xi'an Dian Tong Software Co., Ltd. All Rights Reserved.
* @Version 1.0
*/
@Data
@ApiModel
public class CommunicationEditData<T,L> { @ApiModelProperty(value = " Basic style ")
@JsonProperty("base")
private Formstyle<T> base; @ApiModelProperty(value = " Communication address style ")
@JsonProperty("communicationConfig")
private Formstyle<L> communicationConfig;
}

But these two Formstyle The attributes inside are inconsistent , So we need to define two generics separately

The two generics above , In fact, it can be done through the data table dao Entity class control , Just pass it directly to the entity class . But for the sake of convenience , I defined two generics <T> BaseGenericEditData,<L> CommunicationGenericEditData

BaseGenericEditData:

@Data
@ApiModel
public class BaseGenericEditData<T> { @ApiModelProperty(value = " name ")
private T name; @ApiModelProperty(value = " Whether to use it with Zoomlion BH")
@JsonProperty("isOnlyForZlbh")
private T isonlyforzlbh; @ApiModelProperty(value = " remote system id")
@JsonProperty("remoteSystemId")
private T remotesystemid; @ApiModelProperty(value = " postal address ")
@JsonProperty("communicationAddress")
private T communicationaddress; @ApiModelProperty(value = " Communications key")
@JsonProperty("communicationKey")
private T communicationkey; @ApiModelProperty(value = " It works id")
@JsonProperty("validId")
private T validid;
}

CommunicationGenericEditData:

@Data
@ApiModel
public class CommunicationGenericEditData<T> {
@JsonProperty("requestTimes")
@ApiModelProperty(value = " Maximum requests per minute ")
private T requesttimes; @ApiModelProperty(value = " Send timeout ")
private T overtime; @ApiModelProperty(value = " Reconnection ")
@JsonProperty("isReconnection")
private T isreconnection; @ApiModelProperty(value = " Automatic reconnection ")
@JsonProperty("reconnectionTimes")
private T reconnectiontimes; @ApiModelProperty(value = " The number of automatic reconnections ")
@JsonProperty("reconnectionInterval")
private T reconnectioninterval; @ApiModelProperty(value = " The log level ")
@JsonProperty("logLevel")
private T loglevel;
}

For example, the transfer in and transfer out rules of small island ,preferenceFields It's shown in lowercase on the front end .

And in the template PreferenceFields It's capital , In this case , It's a legacy of the past , There is no good standard , Cause the case is very random .

In this case , We certainly can't rewrite the whole class just for one field . Now , We just need to inherit Tablestyle, Then rewrite the field .

The data returned is other data

Other complex interfaces , If it includes basic ReturnData attribute , Inherit first , Writing a ReturnData Class to do other extended properties , Otherwise, according to the specific situation , Customize ReturnData

give an example 1

Island mailing address :getFromDataForAddOrUpdata

No integration Swagger Before , The return value generic is JSONObjec, Go straight back to jsonRes

After integration , Generic JSONObject It becomes a concrete object Communication< > object

Back to front end style data integration Swagger More articles about

  1. django Study -16. The data returned to the front page is json Data type 3 Kind of plan

    Directory structure 1. Preface 2.JsonResponse Class source code simple analysis 2.1.JsonResponse The source code of the class is as follows 2.2.JsonResponse The general meaning and function of each input parameter in the class constructor 3.[ programme ...

  2. export excel, And return the data to the front end ( Including authority judgment )

    One . First write the Export button interface 1. This interface judges the user's permission 2. This interface pieces the front-end parameter combination to the next interface url In the middle , For conditional screening 3. If the user has permission, save the user's permission information to redis In the middle , And will token writes ...

  3. sessionStorage Record the data returned to the front end , Used to solve the problem of login interceptor refreshing page

    1. The scene and solution of the problem Implement a login interceptor , rewrite doFilter Method , Judge the user's login status , When the user does not operate for a long time or logs in from other places, the front end will prompt , The complete code is as follows public class LoginValida ...

  4. [ Front and rear end separation project ]thinkphp The data returned to the front end is a string

    Write it at the front : Now most of the projects are developed in the mode of front-end and back-end separation , The development in this mode greatly improves the work efficiency , And the format of the front-end and back-end data interactive transmission is basically json Mainly , In the graduation project, both front-end development and back-end development are taken into account ( Back end Xiaobai one ), Front end business ...

  5. SpringBoot + Vue + ElementUI Realize the background management system template -- Back end ( One ): Build a basic environment 、 Integrate Swagger、MyBatisPlus、JSR303 And international operations

    relevant (1) Related blog address : SpringBoot + Vue + ElementUI Realize the background management system template -- Front end ( One ): Build a basic environment :https://www.cnblogs.com/l-y- ...

  6. Spring Boot First time to know (3)- Spring Boot Integrate Swagger

    One . In this paper, If Web If the project is completely front-end and back-end separated ( I think it's a trend now to completely separate the front end from the back end ) Generally, the interaction between the front end and the back end is through the interface , The document describing the input and output parameters of the interface is Mock file . With the increase of the number of interfaces and parameters ...

  7. Xiao Fan's notes :ASP.NET Core API Basic knowledge and Axios Front end submit data

    Work with colleagues to separate front and back projects , I'm right WebApi A lot of knowledge is not enough , It's not necessary to learn the whole stack , But also to understand the basic knowledge , In order to design the interface reasonably .API, Convenient handover with front end . After returning to dormitory at night , Yes WebApi Knowledge leakage and deficiency , ...

  8. SpringBoot Integrate Swagger and Actuator

    Preface This article mainly introduces SpringBoot Integrate Swagger(API Document generation framework ) and SpringBoot Integrate Actuator( Project monitoring ) Use the tutorial . SpringBoot Integrate Swagger explain : Such as ...

  9. SpringBoot The integration of learning Swagger

    Swagger Introduce 1. What is? Swagger As a back-end program development , We have more or less written a few background interface projects , Whether it's writing a mobile interface , It is still a hot front and back separation project , The front end and back end are developed by different Engineers , So this is ...

  10. The solution is Use AjaxFileUploder When the plug-in , Cannot get the returned json Results data

    stay MVC  project Use in AjaxFileUploader This plug-in , When uploading pictures or files , What is returned in the controller is json data , But in the ie, or googleChrome In the browser Back to json ...

Random recommendation

  1. speech recognition resource

    sirius http://sirius.clarity-lab.org/sirius/#install $ tar xzf sirius-1.0.1.tar.gz $ cd sirius/siriu ...

  2. (adhoc) process launch failed: timed out waiting for app to launch

    I had a similar issue when trying to debug an App with Ad-Hoc provisioning... Check which provisioni ...

  3. 【bzoj1036】 ZJOI2008— Statistics of trees Count

    http://www.lydsy.com/JudgeOnline/problem.php?id=1036 ( Topic link ) The question Dynamically maintain the maximum weight and weight sum between two points on the tree . Solution Chain partition of bare tree . this ...

  4. 【BZOJ】【1027】【JSOI2007】 Alloy

    Computational geometry / convex hull /Floyd Orz rausen I'm too spicy I really can't do computational geometry >_> This question …… Although he gave 3 A coordinate , But it's actually a two-dimensional computational geometry problem = = Because the first two dimensions can be used directly for the third dimension ...

  5. 《C And a pointer 》 Reading notes —— Chapter one Quick start

    1. Comment code can use : #if 0 statements #endif 2. The parameter is declared as const, Indicates that the function will not modify the parameter passed by the function caller . 3.scanf("%d",&am ...

  6. stay WPF Customize your drawing in ( Two )

    original text : stay WPF Customize your drawing in ( Two )   stay WPF Customize your drawing in ( Two )                                                                 ...

  7. HTTP POST Requested Apache Rewrite Rule settings

    Recently, when self testing the back-end module, there is a business need to take advantage of WebServer( I use it Apache) take HTTP POST The request is forwarded to the back end C modular , The back end processes and returns 2 Binary encrypted data .http post Requested url The format is :     ...

  8. ThinkPHP In the template engine volist label

    Volist Tags are mainly used to loop out datasets or multidimensional arrays in templates You have to have :name attribute , The data template variable to output ,id Is a cyclic variable . See the development manual for other properties . Usually the model's select Method returns a two-dimensional result ...

  9. IIS One click Install and uninstall

    IIS6: Apply to win server 2003:: ******************* :: * install :: ******************* :Install Cls @echo. &am ...

  10. [20190324] strange GV$FILESPACE_USAGE View .txt

    [20190324] strange GV$FILESPACE_USAGE View .txt--// Find out GV$FILESPACE_USAGE The definition is strange , Make a record .1. Environmental Science :[email protected]> @ ver1P ...