我需要调用一个超级构造函数,它要求我传递.class泛型类型的引用.我怎样才能用Java实现这一目标?
构造函数想拥有..
Class<List<MyType>>
Run Code Online (Sandbox Code Playgroud)
由于泛型在运行时被擦除,我不知道如何满足构造函数.
List<MyType>.class // does not work ;-)
Run Code Online (Sandbox Code Playgroud) 是否可以<persistence-unit-metadata>通过Java API 访问信息?
<persistence-unit-metadata>
<persistence-unit-defaults>
<schema>MySchema</schema>
</persistence-unit-defaults>
</persistence-unit-metadata>
Run Code Online (Sandbox Code Playgroud)
我想通过JPA API或EclipseLink API阅读模式"MySchema",这是我使用的实现.
类似于:entityManager.getDefaults().getSchema(); 可以投射或使用任何EclipseLink类,这对此很好.
谢谢
我正在寻找一种方法来包装我的服务的任何响应.
我有一个简单的服务,有很多不同的方法,像这样
@Path(value = "/listSomething/{apiKey:.+}")
public List<ObjectA> listSomething(@PathParam(value = "apiKey") String apiKey)
Run Code Online (Sandbox Code Playgroud)
一些返回列表,一些只是一些普通对象.我现在想要实现的是用一些状态信息(例如下面)包围它们周围的任何响应.
response {
staus: "OK",
data: {..the actual response..}
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用一些拦截器实现这一点,但我没有成功(除非我添加@XmlSeeAlso注释,我真的不想要的,因为我想要一些通用的方法).我的包装类看起来像:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
//@XmlSeeAlso(ResponseA.class)
public class ResponseWrapper {
boolean error;
String message;
@XmlAnyElement(lax = true)
Object object;
public boolean isError() {
return error;
}
public void setError(boolean error) {
this.error = error;
}
public String getMessage() {
return message;
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了@XmlElement和@XmlAnyElement的不同组合 - 没有任何成功.我在WriterInterceptor和ContainerResponseFilter中尝试了它.
我怎么能做这个简单的伎俩(如果我不需要关心消费者是否需要XML或JSON,那会很酷,但如果我不得不为JSON攻击一些东西,那我就可以了)?
我此刻感觉很丢失.谢谢你的帮助.
我尝试的方法通常得到的错误是UNKOWN_CLASS
{0} nor any of its super class is known …Run Code Online (Sandbox Code Playgroud) 我注意到所有列上都有 colspan 的td内容会影响其他行td的宽度。
谁能解释一下这是为什么以及如何让它正常工作?我有两个要求
注意:我正在研究一些 CSS 属性,并发现word-break:break-all可以解决这个问题,但我想了解这个和/或有一个更好的解决方案。
这是带有较长文本的示例:
<table border="1">
<colgroup>
<col>
<col style="width:100%">
</colgroup>
<tr>
<td>aaaaaaaaaaaaaaaaaaaaaa</td>
<td>Take as much space as possible, expand</td>
</tr>
<tr>
<td colspan="2">loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong</td>
</tr>
</table>Run Code Online (Sandbox Code Playgroud)
这里的结果是较短的文本,您可以看到第一行现在不同了。
<table border="1">
<colgroup>
<col>
<col style="width:100%">
</colgroup>
<tr>
<td>aaaaaaaaaaaaaaaaaaaaaa</td>
<td>Take as much space as possible, expand</td>
</tr>
<tr>
<td colspan="2">shorter</td>
</tr>
</table>Run Code Online (Sandbox Code Playgroud)
java ×2
css ×1
eclipselink ×1
generics ×1
html ×1
jax-rs ×1
jax-ws ×1
jaxb ×1
jersey-2.0 ×1
jpa ×1