使用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. SQL 获取时间段内日期列表

    declare @start date,@end date; set @start='2010-01-01'; set @end='2010-02-01'; --获取时间段内日期列表 select [ ...

  2. postman的简单使用

    Postman简单的使用  什么是Postman 在程序开发中用于调试网络程序或者跟踪网页请求.可以对网页进行简单的基本信息调试.Postman最早是作用chrome浏览器插件存在的,但是2018年初 ...

  3. python内存回收的问题

    python实际上,对于占用很大内存的对象,并不会马上释放. 举例,a=range(10000*10000),会发现内存飙升一个多G,del a 或者a=[]都不能将内存降下来.. del 可以删除多 ...

  4. File operations 1

    1:只读(‘r' 和 ’rb'以字节读) f = open('d:\模特主妇护士班主任.txt',mode='r',encoding='UTF-8') content = f.read() print ...

  5. 使用fiddler模拟控制网速,实现网速慢。(丢包如何模拟)

    参考连接 https://blog.csdn.net/baidu_zhongce/article/details/46683323 参考连接2 https://www.jianshu.com/p/b9 ...

  6. SkiaSharp图像处理

    SkiaSharp图像处理 .NET Core使用skiasharp文字头像生成方案(基于docker发布)   一.问题背景 目前.NET Core下面针对于图像处理的库微软并没有集成,在.NET ...

  7. 分布式存储ceph——(4)ceph 添加/删除osd

    一.添加osd: 当前ceph集群中有如下osd,现在准备新添加osd:

  8. Linux下的crontab

    Ubuntu服务器/var/log下没有cron日志,这里记录一下如何ubuntu server如何查看crontab日志 crontab记录日志 修改rsyslog sudo vim /etc/rs ...

  9. PHP实现部分字符隐藏

    /** * 隐藏部分字符串 * # 此方法多用于手机号码或身份证号.银行卡号的中间部分数字的隐藏 */ function func_substr_replace($str, $replacement ...

  10. video标签,在移动端获取第一帧作为展示

    写在前面 video标签,获取第一帧作为poster.网上能找着很多案例,很容易实现,在pc端 效果明显.但是在移动端,这些实现方式并不能起作用.原因是 移动端 对video标签的限制,许多video ...