公司数据对接国内某知名股票机构,需要提供接口按Rss方式返回结果,开始首次尝试实现。
Really Simple Syndication 简易信息聚合(也叫聚合内容)是一种基于XML的标准。简单来说就是网站提供按Rss方式返回结果的接口,方便RSS订阅器订阅;将一些自己关注的信息整合在一起【个人理解】
SpringBoot 2.1.2.RELEASE
JDK 1.8
Maven 3.5.0
Spring boot 入门 使用rome实现RSS 订阅
SpringMVC返回RSS格式的XML数据
因版本问题,依赖不完整造成报错,具体依赖下文会讲。
<!--ROAM依赖 RSS 订阅-->
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome</artifactId>
<version>1.15.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.rometools/rome-utils -->
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome-utils</artifactId>
<version>1.15.0</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>2.0.6</version>
</dependency>
第一篇大神文章中只引入rome包。我参考尝试的时候,会报ClassNotFoundException错误。
在Item类中使用的Dates,Lists是在utils包中。所以需要引入rome-utils这个包。(建议与rome包版本一致)
同样也需要引入jdom2解析包。
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.*;
import com.fang.cloud.api.sn.ApiSn;
import io.swagger.annotations.ApiOperation;
/**
* @author: guochao.bj
* @create: 2021-05-08 13:12:33
*/
public interface FeedControllerApi {
@ApiSn("55da7417-c310-4fcf-918a-c6857999b279")
@GetMapping(value = "/getRankDescriptionRss/{dataSourceType}/{dataDate}", produces = "application/xml;charset=UTF-8")
@ApiOperation(value = "获取top10排名文字说明【RSS 订阅】", notes = "[email protected]", httpMethod = "GET",
produces = "application/xml;charset=UTF-8")
@ApiImplicitParams({
@ApiImplicitParam(name = "dataSourceType", value = "数据来源类型(1(土地),2(销售))",required = true, dataType = "int"),
@ApiImplicitParam(name = "dataDate", value = "数据时间(yyyy-mm)", required = true,dataType = "String")
})
@ResponseBody
String getRankDescriptionRss(@PathVariable("dataSourceType") Integer dataSourceType, @PathVariable("dataDate") String dataDate);
}
import com.fang.industry.dto.bizpr.description.RankDescriptionDto;
import com.fang.industry.service.bizpr.http.controllerapi.FeedControllerApi;
import com.fang.industry.serviceiface.bizpr.IRankDescriptionService;
import com.rometools.rome.feed.rss.*;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.WireFeedOutput;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @author: [email protected]
* @createDate: 2021/5/8 13:17
*/
@RestController
@RequestMapping("/feed")
@Api(description = "获取top10排名文字说明【RSS 订阅】")
public class FeedController implements FeedControllerApi {
@Autowired
IRankDescriptionService rankDescriptionService;
@Override
public String getRankDescriptionRss(@PathVariable("dataSourceType") Integer dataSourceType, @PathVariable("dataDate") String dataDate) {
Date date = new Date();
Channel channel = new Channel("rss_2.0");
channel.setTitle("CIH-Top10");
String title=null;
if (dataSourceType==1){
channel.setDescription("CIH-Top10 拿地榜文字说明");
title="拿地榜";
}else if (dataSourceType==2){
channel.setDescription("CIH-Top10 销售榜文字说明");
title="销售榜";
}
channel.setLink("https://www.fang.com");
channel.setGenerator("CIH");
channel.setEncoding("Utf-8");
channel.setPubDate(date);
List items = new ArrayList();
List<RankDescriptionDto> rankDescription = rankDescriptionService.getRankDescription(dataDate, dataSourceType);
for (RankDescriptionDto rankDescriptionDto : rankDescription) {
Item item = new Item();
item.setAuthor("CIH");
item.setTitle(title);
Description desc = new Description();
desc.setValue(rankDescriptionDto.getSummaryDescriptionText());
item.setDescription(desc);
items.add(item);
}
channel.setItems(items);
WireFeedOutput out = new WireFeedOutput();
String str = "";
try {
str = out.outputString(channel);
} catch (FeedException ex) {
return "返回失败,联系管理员";
}
return str;
}
首次实现,理解不深,请多指教
文章浏览阅读1k次。通过使用ajax方法跨域请求是浏览器所不允许的,浏览器出于安全考虑是禁止的。警告信息如下:不过jQuery对跨域问题也有解决方案,使用jsonp的方式解决,方法如下:$.ajax({ async:false, url: 'http://www.mysite.com/demo.do', // 跨域URL ty..._nginx不停的xhr
文章浏览阅读2k次。关于在 Oracle 中配置 extproc 以访问 ST_Geometry,也就是我们所说的 使用空间SQL 的方法,官方文档链接如下。http://desktop.arcgis.com/zh-cn/arcmap/latest/manage-data/gdbs-in-oracle/configure-oracle-extproc.htm其实简单总结一下,主要就分为以下几个步骤。..._extproc
文章浏览阅读1.5w次。linux下没有上面的两个函数,需要使用函数 mbstowcs和wcstombsmbstowcs将多字节编码转换为宽字节编码wcstombs将宽字节编码转换为多字节编码这两个函数,转换过程中受到系统编码类型的影响,需要通过设置来设定转换前和转换后的编码类型。通过函数setlocale进行系统编码的设置。linux下输入命名locale -a查看系统支持的编码_linux c++ gbk->utf8
文章浏览阅读750次。今天准备从生产库向测试库进行数据导入,结果在imp导入的时候遇到“ IMP-00009:导出文件异常结束” 错误,google一下,发现可能有如下原因导致imp的数据太大,没有写buffer和commit两个数据库字符集不同从低版本exp的dmp文件,向高版本imp导出的dmp文件出错传输dmp文件时,文件损坏解决办法:imp时指定..._imp-00009导出文件异常结束
文章浏览阅读143次。当下是一个大数据的时代,各个行业都离不开数据的支持。因此,网络爬虫就应运而生。网络爬虫当下最为火热的是Python,Python开发爬虫相对简单,而且功能库相当完善,力压众多开发语言。本次教程我们爬取前程无忧的招聘信息来分析Python程序员需要掌握那些编程技术。首先在谷歌浏览器打开前程无忧的首页,按F12打开浏览器的开发者工具。浏览器开发者工具是用于捕捉网站的请求信息,通过分析请求信息可以了解请..._初级python程序员能力要求
文章浏览阅读7.6k次,点赞2次,收藏6次。@Service标注的bean,类名:ABDemoService查看源码后发现,原来是经过一个特殊处理:当类的名字是以两个或以上的大写字母开头的话,bean的名字会与类名保持一致public class AnnotationBeanNameGenerator implements BeanNameGenerator { private static final String C..._@service beanname
文章浏览阅读3k次,点赞4次,收藏14次。Java软件工程师职位分析_java岗位分析
文章浏览阅读2k次。Java:Unreachable code的解决方法_java unreachable code
文章浏览阅读1w次。1、html中设置标签data-*的值 标题 11111 222222、点击获取当前标签的data-url的值$('dd').on('click', function() { var urlVal = $(this).data('ur_如何根据data-*属性获取对应的标签对象
文章浏览阅读6.9w次,点赞73次,收藏463次。1.前序创建#include<stdio.h>#include<string.h>#include<stdlib.h>#include<malloc.h>#include<iostream>#include<stack>#include<queue>using namespace std;typed_二叉树的建立
文章浏览阅读7.1k次。在Asp.net上使用Excel导出功能,如果文件名出现中文,便会以乱码视之。 解决方法: fileName = HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);_asp.net utf8 导出中文字符乱码
文章浏览阅读2.1k次,点赞4次,收藏23次。第一次实验 词法分析实验报告设计思想词法分析的主要任务是根据文法的词汇表以及对应约定的编码进行一定的识别,找出文件中所有的合法的单词,并给出一定的信息作为最后的结果,用于后续语法分析程序的使用;本实验针对 PL/0 语言 的文法、词汇表编写一个词法分析程序,对于每个单词根据词汇表输出: (单词种类, 单词的值) 二元对。词汇表:种别编码单词符号助记符0beginb..._对pl/0作以下修改扩充。增加单词