How to Develop a java open-source framework ----- automatically generate online documents based on the implementation of the Jvn framework (Lecture 7) ----- Lecture 7 of jvn

Source: Internet
Author: User

How to Develop a java open-source framework ----- automatically generate online documents based on the implementation of the Jvn framework (Lecture 7) ----- Lecture 7 of jvn

I,

The blogger is teaching you how to develop a javaEE framework. I name the framework Jvn, And the blog has a complete development video. Every blog post is a knowledge point;

About the framework of the introduction and learning, you can start from the first lecture of my blog, blog home: http://www.cnblogs.com/everxs/

This content video and source code: http://pan.baidu.com/s/1o6MJnFc

 

II,

Content of this blog

Scenario: In the APP era, apps are popular, and HTTP protocol is used for interaction with the background.

The android Engineer (client) needs a document when calling the background interface. The second background Engineer (JAVA is used here) should maintain this document, or

When writing this document, the workload and maintenance volume are very large. So I raised an idea about whether online documents can be automatically generated.

Solution:

1. Add an annotation @ OnlineController to our Controller and specify the purpose of the annotation Controller memo = "user management COntroller". The URL of this Controller

2. Add the @ OnlineMethod annotation to our specific Action, that is, the method in our Controller, and specify method = "access method (GET or POST )", memo = "method description ",

Param = "parameters required to call this interface, such as: name = XXX & age = XXX", the URL of this interface

3. Save the information to our List and set it to a List when starting the framework.

4. You can define a Controller to obtain the list displayed on the page.

This video with the source code: http://pan.baidu.com/s/1o6MJnFc

We recommend that you watch the video, because it is detailed in the video.

Ps: videos and code will be updated continuously. I hope you will like it and support it a lot.

QQ: 245223343 forever brother eight

The following code is used:

OnlineController:

/** | * Online document Controller annotation * @ author Administrator **/@ Retention (RetentionPolicy. RUNTIME) public @ interface OnlineController {String memo ();}

OnlineMethod:

/*** Online document method annotation * @ author Administrator **/@ Retention (RetentionPolicy. RUNTIME) public @ interface OnlineMethod {String memo (); String param (); String method ();}

Online entity class:

public class Online {private String url;private String memo;private String method;private String param;private int type;public String getUrl() {return url;}public void setUrl(String url) {this.url = url;}public String getMemo() {return memo;}public void setMemo(String memo) {this.memo = memo;}public String getMethod() {return method;}public void setMethod(String method) {this.method = method;}public String getParam() {return param;}public void setParam(String param) {this.param = param;}public int getType() {return type;}public void setType(int type) {this.type = type;}}

OnlineDoc operation class:

Public class OnlineDoc {/*** load the annotated Controller */public static List <Online> loadClass (Map <String, Class> map) {List <Online> onlineList = new ArrayList <Online> (); System. out. println ("map:" + map. size (); for (String nameSpace: map. keySet () {Class clazz = map. get (nameSpace); OnlineController onlineController = (OnlineController) clazz. getAnnotation (OnlineController. class); if (onlineController! = Null) {System. out. println ("in"); Online online = new Online (); online. setType (1); online. setMemo (onlineController. memo (); online. setUrl (nameSpace); onlineList. add (online); Method [] methods = clazz. getMethods (); for (Method method: methods) {OnlineMethod onlineMethod = method. getAnnotation (OnlineMethod. class); if (onlineMethod! = Null) {Online o = new Online (); o. setMemo (onlineMethod. memo (); o. setMethod (onlineMethod. method (); o. setParam (onlineMethod. param (); o. setType (2); o. setUrl (nameSpace + "/" + method. getName (); onlineList. add (o) ;}}} System. out. println ("How many are executed:" + onlineList. size (); return onlineList ;}}

Finally, configure the online documentation:

public class OnlineDocController extends JvnController{public void index(){List<Online> onlineList = JvnConfig.CONSTANT.getOnlineList();System.out.println("size :" +onlineList.size());getRequest().setAttribute("onlineList", onlineList);render("/WEB-INF/views/online/index.jsp");}}

Test Controller:

@ OnlineController (memo = "order management controller") public class OrderController extends JvnController {@ OnlineMethod (memo = "add order", method = "GET ", param = "Order id orderId") public void add () {}@ OnlineMethod (memo = "delete order", method = "GET", param = "Order id orderId ") public void delete (){}}

Jsp of online documents:

<% @ Page import = "com.jvn.doc. online. online "%> <% @ page language =" java "contentType =" text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> <% @ taglib prefix =" c "uri =" http://java.sun.com/jsp/jstl/core "%> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> 

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.