我已经使用 jersey 实现了 REST 服务。当响应的 mime-type 为“text/xml”时,有没有办法指定关联的 xml-stylesheet ?
谢谢。
更新:这是代码片段:
@Path("/service")
@Stateless
public class MyServices
{
@PersistenceContext(unitName = "em")
private EntityManager em;
@Path("/id/{id}")
@GET
public MyClass getById(@PathParam("id")long id)
{
MyClass o=em.find(MyClass.class, id);
return o;
}
}
.
@Entity(name="X")
@XmlRootElement(name="X")
@NamedQueries(...)
public class MyClass
implements Serializable
{
private static final long serialVersionUID = 1L;
...
}
最佳答案
参见:Is there a way to modify Jersey generated XML response to include stylesheet info?
有一个不错的XmlHeader与 JAXB 配合良好的注释。
@Path("/id/{id}")
@GET
@Produces("application/xml")
@XmlHeader("<?xml-stylesheet type=\"text/css\" href=\"something.css\"?>")
public MyClass getById(@PathParam("id")long id)
关于java - JAX-RS/ Jersey +文本/xml : can I specify a xml-stylesheet?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14739303/