How to develop a Java open source framework-----The implementation of the JVN framework automatically generate online documentation (seventh)

Source: Internet
Author: User

One

foreword: Bo Master is teaching everyone how to develop a Java EE Framework, I named the framework JVN, the blog has a complete development video, each blog is a knowledge point;

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

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

Two

What this blog is about

Scenario: It's the app era, apps are hot, and interacting with the background is the HTTP protocol, so here's the interaction.

Android Engineer (client), when invoking the background interface, need a document, two background engineer (here in Java), to maintain the document, or

The volume of work and maintenance is very large, says the handwritten document. So the idea is that online documents can be generated automatically.

Solution Ideas :

1, add an annotation to our controller @onlinecontroller also specify the purpose of the annotated controller memo= "User Management Controller", the controller's URL

2, add a @onlinemethod annotation to our specific action, which is the method inside our controller, and specify method= "access mode (GET or Post)", memo= "method description",

param= "Call this interface requires parameters such as: Name=xxx&age=xxx", the URL of the interface

3. Save this information in our list and set it in a list when the frame is launched.

4, the user can define a controller to get the list displayed on the page

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

It is recommended to watch the video, because I spoke in detail in the video.

Ps: Video and code will continue to update, I hope you like, a lot of support.

qq:245223343 Forever Starling.

Here are some of the code:

Onlinecontroller:

/**| * Online Document Controller annotations * @author Administrator * */@Retention (retentionpolicy.runtime) public @interface Onlinecontroller { String memo ();}

Onlinemethod:

/** * Method notes for online documentation * @author Administrator * * * * * * * * @Retention (retentionpolicy.runtime) public @interface Onlinemethod {String mem O (); 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;pu Blic 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 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); O Nlinecontroller Onlinecontroller = (onlinecontroller) clazz.getannotation (Onlinecontroller.class); Onlinecontroller!=null) {System.out.println ("come 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 ("The number of executions:" +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 for online Documentation:

<% @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" >

  

How to develop a Java open source framework-----The implementation of the JVN framework automatically generate online documentation (seventh)

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.