使用RESTful API可以更好的开发前后分离的应用,后面一节会介绍使用模版引擎Beetl开发后端渲染的应用。

一、配置Swagger(Api 接口文档)

1、使用系统自带

拷贝jeesite-modules-swagger中的config.SysApiConfig和swagger.config.SwaggerComfig到com.jeesite.modules下面

将SysApiConfig修改为CmsApiConfig

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
// package com.jeesite.modules.config; import com.jeesite.modules.swagger.config.SwaggerConfig;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spring.web.plugins.Docket; @Configuration
@ConditionalOnProperty(
name = {"web.swagger.enabled"},
havingValue = "true",
matchIfMissing = false
)
public class CmsApiConfig {
public CmsApiConfig() {
} @Bean
public Docket cmsApi() {
String moduleCode = "cms";
String moduleName = "内容模块";
String basePackage = "com.jeesite.modules.cms.web";
return SwaggerConfig.docket(moduleCode, moduleName, basePackage).select().apis(RequestHandlerSelectors.basePackage(basePackage)).build();
}
}

SwaggerConfig根据需要修改

2、自己配置

pom.xml

swagger
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>

SwaggerConfig.java

package com.jeesite.modules.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket; /**
*
* @author Vito
*
*/
@Configuration
public class SwaggerConfig { @Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.groupName("yuosc-api")
.select()
.apis(RequestHandlerSelectors.basePackage("com.jeesite.modules.cms.web"))
.paths(PathSelectors.any())
.build();
} private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("YUOSC API")
.description("YUOSC<a href='http://vote.yangtzeu.edu.cn' target='_blank'>门户</a>" +
"和<a href='http://localhost:8980/index' target='_blank'>博客</a>的API文档")
// .termsOfServiceUrl("http://localhost:8980/index")
.version("1.0")
.build();
}
}

在Application启动容器加注解@EnableSwagger2

此种方式可以查看下面两篇文章

使用swagger作为restful api的doc文档生成

SpringBoot(七):SpringBoot整合Swagger2

二、写接口程序

此时返回前端的是实体json

/**
* 首页内容(获取top5文章)
* @param
* @return
*/
@ApiOperation(value="首页内容(获取top5文章)", notes="获取最新top5文章")
@GetMapping(value = "/index")
public JsCmsResponse index(JsCmsResponse resp) throws Exception {
List<JsCmsArticlesEntity> articles = this.frontService.getAllArticles();
resp.setRespCode(JsCmsResponse.RESPCODE_SUCCESS);
resp.setMsgInfo("获取内容成功");
resp.setRespObj(articles);
return resp;
}

三、http://localhost:8980/swagger-ui.html

基于jeesite的cms系统(三):使用RESTful API在前端渲染数据的更多相关文章

  1. 基于jeesite的cms系统(一):开发环境搭建

    基于jeesite的cms系统系列,是对基于jeesite进行二次开发的博客模块开发过程的总结.涉及入门安装,二次开发,部署等 一.概况: JeeSite 是一个 Java 企业级快速开发平台,基于经 ...

  2. 基于jeesite的cms系统(四):使用Beetl模版引擎在后端渲染数据

    一.Beetl简介 1. 什么是Beetl Beetl目前版本是2.9.3,相对于其他java模板引擎,具有功能齐全,语法直观,性能超高,以及编写的模板容易维护等特点.使得开发和维护模板有很好的体验. ...

  3. 基于jeesite的cms系统(五):wangEditor富文本编辑器

    一.关于wangEditor: wangEditor —— 轻量级 web 富文本编辑器,配置方便,使用简单.支持 IE10+ 浏览器. 官网:www.wangEditor.com 文档:www.ka ...

  4. 基于jeesite的cms系统(二):整体设计

    一.菜单设计 在系统管理-菜单管理中可以设置内容管理菜单(自动生成) 注意:归属模块应属于核心模块core.如果新加的的菜单设置为内容管理模块cms,系统下次重启时会重置本次设置,具体原因不详. 二. ...

  5. 基于jeesite的cms系统(七):GlobalException全局异常和部署

    关于全局异常: 在业务代码中专注处理业务,而不是返回各种CodeMsg(比如这里只需要知道登录时成功还是失败,其余情况直接抛出异常),可以直接抛出异常,添加一个全局异常类,根据CodeMsg来生成异常 ...

  6. 基于jeesite的cms系统(六):Lucene全文搜索引擎

    1.lucene初始化 // @Value("${lucene.index.path}") private String indexPath = "/Users/vito ...

  7. 4- vue django restful framework 打造生鲜超市 -restful api 与前端源码介绍

    4- vue django restful framework 打造生鲜超市 -restful api 与前端源码介绍 天涯明月笙 关注 2018.02.20 19:23* 字数 762 阅读 135 ...

  8. 基于Node的PetShop,oauth2认证RESTful API

    前篇 - 基本认证,用户名密码 后篇 - OAuth2 认证 前文使用包passport实现了一个简单的用户名.密码认证.本文改用oauth2来实现更加安全的认证.全部代码在这里. OAUTH2 用户 ...

  9. 一百零一:CMS系统之自定义restful风格json返回格式和内容

    鉴于flask-restful用起来太麻烦,这里自定义json统一返回格式和内容 from flask import jsonify class HttpCode: """ ...

随机推荐

  1. 前端开发之基础知识-HTML(一)

    1.1 html概述和基本结构 html概述 HTML是 HyperText Mark-up Language 的首字母简写,意思是超文本标记语言,超文本指的是超链接,标记指的是标签,是一种用来制作网 ...

  2. EF6实现软删除

    https://www.jianshu.com/p/c65fbfe16e1a

  3. C语言之各个位数上的数值之和

    #include<stdio.h> #include<stdlib.h> void main() { int num; ; int x,y; printf("请输入一 ...

  4. (poj 3662) Telephone Lines 最短路+二分

    题目链接:http://poj.org/problem?id=3662 Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total ...

  5. 证明与计算(3): 二分决策图(Binary Decision Diagram, BDD)

    0x01 布尔代数(Boolean algebra) 大名鼎鼎鼎的stephen wolfram在2015年的时候写了一篇介绍George Boole的文章:George Boole: A 200-Y ...

  6. ubuntu搭建JavaEE环境

    安装Jave和Tomcat 参考:安装Java和Tomcat 安装eclipse 下载地址:https://www.eclipse.org/downloads/packages/ 我下载的时Eclip ...

  7. MySQL安装后无法用root用户访问的问题

    今天在换了Ubuntu后装个本地的mysql,安装过程没什么好说的:sudo apt-get install mysql-server 安装好了之后我做了以下一系列常规动作: 1.$sudo mysq ...

  8. 2019中山大学程序设计竞赛 Triangle

    今天水了一发hdu上的中山校赛 这个题交了将近十遍才过...... 就是说给 n 个木棍,如果能找出3个能组成三角形的木棍就输出yes 反之输出no 乍一看很简单 一个排序遍历一遍就好了 但是n值太大 ...

  9. 17年iPhone炫酷铃声,mp3、m4r格式下载

    下载链接: https://pan.baidu.com/s/11aj9dBm9upNWpE5jWBgYog

  10. Mint-UI组件 MessageBox为prompt 添加判断条件

    Mint-UI 的Message Box 是prompt类型时,可以添加正则判断或者function判断条件.具体可以查看Mint-UI源码. 添加正则判断条件: MessageBox({ $type ...