【blog】SpringMVC返回RSS格式的XML数据
代码
import com.sun.syndication.feed.rss.Channel;
import com.sun.syndication.feed.rss.Content;
import com.sun.syndication.feed.rss.Description;
import com.sun.syndication.feed.rss.Item;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.WireFeedOutput;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* Author:Mr.X
* Date:2017/11/12 14:01
* Description:
*/
public class RSSUtil {
public static String channleItemXml() {
Date date = new Date();
Channel channel = new Channel("rss_2.0"); // 该type参数为固定格式
channel.setTitle("test rome channel title");
channel.setDescription("channel的描述");
channel.setLink("http://hi.baidu.com/openj/rss");
channel.setPubDate(date);
channel.setEncoding("GBK");
List items = new ArrayList();
Item item = new Item();
item.setAuthor("zhangwei");
item.setTitle("item title");
Description desc = new Description();
desc.setType("item desc type");
desc.setValue("item desc value");
item.setDescription(desc);
items.add(item);// 添加一个item
Item item2 = new Item();
item2.setAuthor("zhangwei");
item2.setTitle("use rome to read rss");
Description desc2 = new Description();
desc2.setValue("you must import rome_1.0.jar & jdom.jar");
item2.setDescription(desc2);
Content content = new Content();
content.setValue("rome是用来发布读取rss的工具,遵循rss标准的XML");
item2.setContent(content);
items.add(item2);// 添加一个item
channel.setItems(items);
WireFeedOutput out = new WireFeedOutput();
String str = "";
try {
str = out.outputString(channel);
} catch (FeedException ex) {
ex.printStackTrace();
}
return str;
}
public static void main(String[] args) {
System.out.println(channleItemXml());
}
}
@GetMapping(value = "feed", produces = "application/xml")
@ResponseBody
public String feed() {
return RSSUtil.channleItemXml();
}
效果

【blog】SpringMVC返回RSS格式的XML数据的更多相关文章
- 关于springmvc返回json格式数据
1.引入maven依赖 <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifac ...
- springMVC 返回时间格式转换
<mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframewor ...
- Querying Microsoft SQL Server 2012 读书笔记:查询和管理XML数据 1 -使用FOR XML返回XML结果集
XML 介绍 <CustomersOrders> <Customer custid="1" companyname="Customer NRZBB&qu ...
- 加载大量的xml数据 使用压缩方法解决(当然较小时也可以压缩)
如果你的应该程序必须在运行期间加载一个外部大且冗长的XML文件时,这个方案可能是有用的,通过将XML保存为二进制,你可以压缩数据得到一个较小的文件,当然,你可以得到的压缩的数量取决于数据的复杂性,但它 ...
- springmvc返回xml格式、json格式数据
问:@ResponseBody注解怎么指定返回xml 还是json答:@RequestMapping 的produces 属性指定 produces = "application/xml&q ...
- springmvc通过ajax异步请求返回json格式数据
jsp 首先创建index.jsp页面 <script type="text/javascript"> $(function () { $("#usernam ...
- 【Spring学习笔记-MVC-3】SpringMVC返回Json数据-方式1
<Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...
- springmvc 返回xml
需求: 1.springmvc返回xml: 技术及环境: Spring 4.3.1.RELEASE JDK 1.8 IDEA 15.0.6 Maven 3 实现: spirngxml的配置主要如下: ...
- SpringMVC通过实体类返回json格式的字符串,并在前端显示
一.除了搭建springmvc框架需要的jar包外,还需要这两个jar包 jackson-core-asl-1.9.2.jar和jackson-mapper-asl-1.9.2.jar 二.web,. ...
随机推荐
- Summary of Java basics review data
1.标识符 用于命名程序的对象,如方法名,变量名,规则是: a.大小写敏感 b.由英文字符,文字字符,美元符号,下划线和数字组成,但不能以数字开头 c.不能是关键字 2.%:求余运算符 ...
- java利用线程池处理集合
java利用线程池处理集合 2018年07月23日 17:21:19 衍夏成歌 阅读数:866 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/s ...
- opencv mat裁剪
主要记录的就是对Mat裁剪后,新Mat指向的内存和原来的Mat共用. OpenCV入门教程(3)-Mat类之选取图像局部区域
- adb 查看包名或其他
http://blog.sina.com.cn/s/blog_5b478f870102v5bo.html
- MySQL创建方法错误:This function has none of DETERMINISTIC, NO SQL
创建function时 出错信息: ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL ...
- jq实现百度图片移入移出内容提示框上下左右移动的效果
闲来无聊,看到百度图片hover的时候提示框的效果,遂想试一试自己能否实现. 百度图片hover的效果: 需求: 1. 当鼠标从图片上部移入的时候,提示框从上部移到正常位置.从上部移出的时候,提示框从 ...
- docker 基础之私有仓库
docker-registry 是官方提供的工具,可以用于构建私有的镜像仓库.安装运行 docker-registry容器 在安装了 Docker 后,可以通过获取官方 registry 镜像来运行. ...
- mysql的定时任务
参考博客:https://blog.csdn.net/qq_26562641/article/details/53301407 查看event是否开启: show variables like '%s ...
- 16.观察者模式(Observer Pattern)
动机(Motivate): 在软件构建 过程中,我们需要为某些对象建立一种“通知依赖关系” --------一个对象(目标对象)的状态发生改变,所有的依赖对象(观察者对象)都将得到通知.如果这 ...
- 各种loading加载中gif图标
点击这里打包下载更多样式