All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.sergius.apitool.web.WebController Maven / Gradle / Ivy

package com.gitee.sergius.apitool.web;

import com.gitee.sergius.apitool.component.ApiComponent;
import com.gitee.sergius.apitool.constant.Constant;
import com.gitee.sergius.apitool.entity.YamlEntity;
import com.gitee.sergius.apitool.web.html.HtmlOperater;
import com.gitee.sergius.apitool.entity.SubEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @author shawn yang
 * @version 1.0.0
 * 

API页面展示路由控制
* */ @Controller public class WebController { @Autowired private ApiComponent apiComponent; @RequestMapping("/api-doc") public void spiDoc(HttpServletRequest request, HttpServletResponse response){ response.setHeader("Content-type", "text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter writer = null; try{ writer = response.getWriter(); writer.println( "" ); writer.println(" "); writer.println(" "); writer.println(" "); writer.println(" 接口文档 "); writer.println(" "); writer.println(" "); writer.println(" "); writer.println(HtmlOperater.getStylePart()); writer.println(" "); writer.println(" "); Map pamlEntityMap = Constant.yamlEntityMap; if(CollectionUtils.isEmpty(pamlEntityMap)){ writer.println("

No Data !

"); }else{ Iterator tags = pamlEntityMap.keySet().iterator(); while(tags.hasNext()){ String tag = tags.next(); YamlEntity yamlEntity = pamlEntityMap.get(tag); writer.println("

"+tag+"


"); List subEntityList = yamlEntity.getSubEntityList(); if(!CollectionUtils.isEmpty(subEntityList)){ for(SubEntity subEntity : subEntityList){ writer.println(HtmlOperater.getBodyPart(subEntity)); } } writer.println("
"); } } writer.println(" "); writer.println(HtmlOperater.getScriptPart()); writer.println(" "); }catch(IOException e){ e.printStackTrace(); }finally { if(writer != null){ writer.close(); } } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy