使用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. MyDAL - .IsExistAsync() 使用

    索引: 目录索引 一.API 列表 .IsExistAsync() 用于 单表 / 多表连接 查询 二.API 单表-便捷 方法 举例 1.单表-便捷, 判断是否存在方法 var date = Dat ...

  2. MySQL 基础知识梳理学习(六)----锁

    1.什么是锁: 对共享资源进行并发访问控制,提供数据的完整性和一致性. 2.锁的区别: 类型 lock latch 对象 事务 线程 保护 数据库内容 内存数据结构 持续时间 整个事务过程 临界资源 ...

  3. 『cURL』curl: (6) Could not resolve host无法解析主机地址

    最近在学数据挖掘时,获取数据有两种途径: 开放数据,可以直接使用和存储的数据: 网络数据,通过爬虫或云市场api(付费或免费)获取数据 我通过教程,在阿里云购买一个天气数据api,尝试使用cURL获取 ...

  4. [20190416]exclusive latch测试脚本.txt

    [20190416]exclusive latch测试脚本.txt --//昨天做了shared latch的测试脚本,今天完善exclusive latch测试脚本,上个星期的测试我是手工执行的.- ...

  5. Java Memory Management

    How Memory works in Java The role of the stack - Each time you call a function, Java pushed the loca ...

  6. 教你在浏览器里做出EXCEL的效果

    在浏览器里做出EXCEL的效果,复制.粘贴.设置公式.双击编辑等效果,如果自己开发的话,比较麻烦,建议使用成熟的插件.这里介绍使用智表ZCELL插件,实现用户快捷操作. 首先下载插件,引入到页面中,一 ...

  7. C#基础知识之IOC

    依赖注入:http://www.cnblogs.com/leoo2sk/archive/2009/06/17/1504693.html IOC:https://jinnianshilongnian.i ...

  8. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  9. CentOS7.x安装MySQL5.7.25

    mysql 5.7下载地址 社区版下载地址:https://dev.mysql.com/downloads/mysql/ 可能会有变动 找到5.7版本, 注:源码安装需要用到下面的包,可以先忽略,我安 ...

  10. 全面系统讲解CSS 工作应用+面试一步搞定