栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Spring MVC服务Java模型的RDF表示形式?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Spring MVC服务Java模型的RDF表示形式?

假设您正在为MVC应用程序使用注释驱动的配置,这实际上可能非常简单。使用W3C的文本RDF格式的媒体类型问题作为内容类型规范的指南,可以很容易地扩展您现有的解决方案。真正的问题是,当请求RDF时,您需要什么序列化类型?如果我们将Jena用作基础模型技术,则支持任何标准序列化都是非常简单的。杰森是唯一给我带来一点困难的人,但是您已经解决了这个问题。

如您所见,序列化的实现(使用标准的Jena,没有其他库)实际上很容易做到!问题最终只是将适当的序列化与提供的内容类型匹配。

编辑2014年4月19日

先前的内容类型来自捕获工作组讨论的文档。该帖子经过编辑以反映IANA媒体类型注册表的内容类型,并以RDF1.1
N-Triples
和JSON-
LD
标准为补充。

@Controllerpublic class SpecialController {    public Model model = null; // set externally    @RequestMapping(value="your/service/location", method=RequestMethod.GET, produces={"application/x-javascript", "application/json", "application/ld+json"})    public @ResponseBody String getModelAsJson() {       // Your existing json response    }    @RequestMapping(value="your/service/location", method=RequestMethod.GET, produces={"application/xml", "application/rdf+xml"})    public @ResponseBody String getModelAsXml() {       // Note that we added "application/rdf+xml" as one of the supported types       // for this method. Otherwise, we utilize your existing xml serialization    }    @RequestMapping(value="your/service/location", method=RequestMethod.GET, produces={"application/n-triples"})    public @ResponseBody String getModelAsNTriples() {       // New method to serialize to n-triple       try( final ByteArrayOutputStream os = new ByteArrayOutputStream() ){model.write(os, "N-TRIPLE");return os.toString();       }    }    @RequestMapping(value="your/service/location", method=RequestMethod.GET, produces={"text/turtle"})    public @ResponseBody String getModelAsTurtle() {       // New method to serialize to turtle       try( final ByteArrayOutputStream os = new ByteArrayOutputStream() ){model.write(os, "TURTLE");return os.toString();       }    }    @RequestMapping(value="your/service/location", method=RequestMethod.GET, produces={"text/n3"})    public @ResponseBody String getModelAsN3() {       // New method to serialize to N3       try( final ByteArrayOutputStream os = new ByteArrayOutputStream() ){model.write(os, "N3");return os.toString();       }    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/417165.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号