代码

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数据的更多相关文章

  1. 关于springmvc返回json格式数据

    1.引入maven依赖 <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifac ...

  2. springMVC 返回时间格式转换

    <mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframewor ...

  3. Querying Microsoft SQL Server 2012 读书笔记:查询和管理XML数据 1 -使用FOR XML返回XML结果集

    XML 介绍 <CustomersOrders> <Customer custid="1" companyname="Customer NRZBB&qu ...

  4. 加载大量的xml数据 使用压缩方法解决(当然较小时也可以压缩)

    如果你的应该程序必须在运行期间加载一个外部大且冗长的XML文件时,这个方案可能是有用的,通过将XML保存为二进制,你可以压缩数据得到一个较小的文件,当然,你可以得到的压缩的数量取决于数据的复杂性,但它 ...

  5. springmvc返回xml格式、json格式数据

    问:@ResponseBody注解怎么指定返回xml 还是json答:@RequestMapping 的produces 属性指定 produces = "application/xml&q ...

  6. springmvc通过ajax异步请求返回json格式数据

    jsp 首先创建index.jsp页面 <script type="text/javascript"> $(function () { $("#usernam ...

  7. 【Spring学习笔记-MVC-3】SpringMVC返回Json数据-方式1

    <Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...

  8. springmvc 返回xml

    需求: 1.springmvc返回xml: 技术及环境: Spring 4.3.1.RELEASE JDK 1.8 IDEA 15.0.6 Maven 3 实现: spirngxml的配置主要如下: ...

  9. SpringMVC通过实体类返回json格式的字符串,并在前端显示

    一.除了搭建springmvc框架需要的jar包外,还需要这两个jar包 jackson-core-asl-1.9.2.jar和jackson-mapper-asl-1.9.2.jar 二.web,. ...

随机推荐

  1. 关于Java中扫描仪next()与nextLine()的区别

    首先,next()一定要读取到有效字符后才可以结束输入,对输入有效字符之前遇到的空格键.Tab键或Enter键等结束符,next()方法会自动将其去掉,只有在输入有效字符之后,next()方法才将其后 ...

  2. Unable to load script from assets 'index.android.bundle'.make sure you bundle is packaged correctly

    解决此问题 以下方法每次都需要执行命令2才能更新 1.创建assets目录 mkdir android/app/src/main/assets 2.执行命令 react-native bundle - ...

  3. Linux:不同文件相同列字符合并文件(awk函数)

    存在file1.txt,其内容如下: H aa 0 0 1 -9 H bb 0 0 2 -9 H cc 0 0 2 -9 存在file2.txt,其内容如下: H aa 0 0 0 -9 asd qw ...

  4. redis设置密码以及jedisPool设置密码

    转: redis设置密码以及jedisPool设置密码 2019年01月02日 20:24:43 宇文荒雪 阅读数:1118   版权声明:本文为博主原创文章,未经博主允许不得转载. https:// ...

  5. Day036--Python--线程

    1. 线程 from threading import Thread def func(n): print(n) if __name__ == '__main__': t = Thread(targe ...

  6. shell数组等基本用法

    "shell"既是一种解释型编程语言,也是一个这种编程语言的解释器的名字 shell是解释型语言,就是解释器会一条一条的翻译每一条语句并执行,对比之下,C语言是编译型语言,编译器把 ...

  7. MySql 5.7.23安装

    1.首先上MySql的官网下载  https://dev.mysql.com/downloads/mysql/ 选择源码包: 1. 新建/usr/local/src目录,保存下载的各类安装包 1 mk ...

  8. python自动化开发-[第七天]-面向对象

    今日概要: 1.继承 2.封装 3.多态与多态性 4.反射 5.绑定方法和非绑定方法 一.新式类和经典类的区别 大前提: 1.只有在python2中才分新式类和经典类,python3中统一都是新式类 ...

  9. nlp知识

    1.词集模型 将每个词的出现与否作为一个特征,不考虑词频.也就是一个词在文本在文本中出现1次和多次特征处理是一样的. 2.词袋模型 与词集相比,会考虑词频 sklearn中 CountVectoriz ...

  10. 网络编程基础【day09】:socket实现文件发送(六)

    本节内容 1.概述 2.文件下载实现 3.MD5值校验 一.概述 我们如何利用socket去下载一个文件,整体思路是这样的: 读取文件名 检测文件是否存在 打开文件 检测文件大小 发送文件大小给客户端 ...