我需要添加指向我的 Resteasy api xml 和 json 输出的链接。 所以我写了一个JAXB AtomLink类如下
package samples;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="link", namespace="http://www.w3.org/2005/Atom")
public class AtomLink {
private String rel;
private String href;
private String type;
public AtomLink() {}
public AtomLink(String rel, String href, String type) {
this.rel = rel;
this.href = href;
this.type = type;
}
public AtomLink(String rel, String href) {
this(rel,href,"application/xml");
}
@XmlAttribute
public String getRel() {
return rel;
}
public void setRel(String rel) {
this.rel = rel;
}
@XmlAttribute
public String getHref() {
return href;
}
public void setHref(String href) {
this.href = href;
}
@XmlAttribute
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
并在我的 JAXB xml 或 json 对象中设置链接值。 我得到的输出如下。但链接不可点击。
输出:
<data xmlns:ns2="http://www.w3.org/2005/Atom">
<bucket id="2" name="2012-APR-09 12:05 AM">
<av_data unit="percent" value="100"/>
<data_count unit="#" value="10"/>
<pf_data unit="seconds" value="4.618"/>
</bucket>
<ns2:link href="http://localhost:8080/webapp/api/getrawdata?start=3&size=2" rel="next" type="application/xml"/>
</data>
我应该怎样做才能使链接可点击。
提前致谢。 安妮莎
最佳答案
XML 和 JSON 只是基于文本的数据表示形式。单击链接的能力取决于您用来查看数据的浏览器将该文本的一部分识别为链接并将其呈现为超链接的能力。
关于resteasy - HATEOAS 链接可以点击吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10084398/