我正在尝试编写父pom,并且我定义了一个插件,但我需要更改所有继承实例的配置.所以,我可以在<pluginManagement>
定义中加入一些配置,我可以在其中覆盖它<plugin>
,但是如何让孩子们默认回到<pluginManagement>
版本?
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<executions...>
<configuration>
<configLocation>
(used by all children)
</configLocation>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>
(unique to the parent)
</configLocation>
</configuration>
</plugin>
</plugins>
<build>
Run Code Online (Sandbox Code Playgroud)
那么,会发生什么是孩子继续显示父母的配置.
好吧,我知道C#不支持属性重载 - 大多数参考文献通过引用单方法 - 不同 - 返回类型问题来解释它.然而,怎么样的二传手呢?我想直接将值指定为字符串或对象,但只返回字符串.
像这样:
public string FieldIdList
{
get { return fieldIdList.ToString(); }
set { fieldIdList = new FieldIdList(value); }
}
public FieldIdList FieldIdList
{
set { fieldIdList = value; }
}
private FieldIdList fieldIdList;
Run Code Online (Sandbox Code Playgroud)
为什么不允许这样做?我还看到"属性"只是在编译时创建getter/setter函数.是否可以创建自己的?就像是:
public void set_FieldIdList(FieldIdList value)
{
fieldIdList = value;
}
Run Code Online (Sandbox Code Playgroud)
那会做同样的事情.思考?
我有一个Angular 1.x应用程序,期望使用$http.post()
调用接收二进制文件下载(pdf).问题是,我想要另外得到一个处理错误消息,发送为json.我可以使用配置执行此操作
headers: {
'Accept': 'application/pdf, application/json'
}
Run Code Online (Sandbox Code Playgroud)
问题是我必须设置responseType: 'arraybuffer'
,否则pdf二进制文件被转义(或更改为不加载).但是,这会阻止正确读取或解释json.
我怎么能两个都有?
编辑:我打算澄清一下; 也许我的理解不正确.
$http({
method: 'POST',
url: "/myresource",
headers: {
'Accept': 'application/pdf, application/json'
},
responseType: 'arraybuffer'
})
.then(
function(response) {
// handle pdf download via `new Blob([data])`
}, function(response) {
// pop up a message based on response.data
}
)
Run Code Online (Sandbox Code Playgroud)
在我返回pdf数据块且http状态为200的情况下,第一个函数处理响应并提示用户保存文件.但是,如果状态是错误(422),response.data
则未定义.我认为这是因为responseType
它阻止了json的正确处理.
如果删除该responseType
行,则会正确读取错误数据,但是当保存pdf时,某些文件字节不正确并且实际上已损坏.我认为这是因为文件正在编码,因为javascript期待一个字符串.
好吧,我有一些从基类派生的不同对象,我把它们放在一个列表中.我想遍历列表并将每个推送到一个方法.我对每个类型的签名都有单独的方法,但编译器抱怨.有人可以解释原因吗?这是使用泛型的机会,如果是的话,怎么样?
class Base { }
class Level1 : Base { }
class Level2 : Level1 { }
Run Code Online (Sandbox Code Playgroud)
...
List<Base> oList = new List<Base>();
oList.Add(new Level1());
oList.Add(new Level2());
Run Code Online (Sandbox Code Playgroud)
...
...
foreach(Base o in oList)
{
DoMethod(o);
}
Run Code Online (Sandbox Code Playgroud)
...
void DoMethod(Level1 item) { }
void DoMethod(Level2 item) { }
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我正在尝试使用JAXB 将此文件解组为Java对象.我知道J6中的SAX存在一个问题,即拒绝maxOccurs线,我已将其更改为unbounded
.但是,当我xjc
这样做时,它并没有创建我需要的所有类和枚举.例如,应该有一个educationLevelType
枚举.更重要的是,我尝试了MS的xsd unmarshaller,它正确地创造了一切.
有经验的人比我看这个并且告诉我我缺少的东西吗?是否需要在xsd中更正某些内容,或者JAXB中是否存在错误?
根据要求,更新 Blaise完全回答了这个问题.不幸的是,恕我直言,这使得JAXB毫无价值.整个想法是我可以从模式生成类 - 我不应该事先知道结构的东西.如果我必须创建一个自定义绑定文件,我不妨创建一个生成我想要的代码的模式.但那么,为什么要停在那里?为什么不跳过所有这些步骤并生成我想要的类?
最后,一位同事向我指出了Apache XMLBeans--该项目有点旧,但它创建的对象没有任何问题.Codehaus还有一个xmlbeans-maven-plugin.
我一直在使用 Spring JPA Repository 接口来持久化对象,而且效果非常好!@Entity
但是当定义了一个时我该如何使用它@IdClass
?类不是嵌入的,但字段是对象的一部分。我是否应该创建findBy
命名所有复合字段的方法?或者有没有办法创建findById
并通过 PK 类?
在查看Spring Data JPA 存储库的查询创建时,我想知道如何重用参数。例如,如果我想做类似的事情,我将如何命名该方法:
@Query("select c from #{#entityName} c where c.lower <= ?1 and c.upper >= ?1")
E findByConversionFor(Double amount);
Run Code Online (Sandbox Code Playgroud)
该查询是否可以转换为 SpEL 方法名称(由查询构建器使用)?
要求将相同的值传递两次似乎是一种拼凑:
E findByLowerLessThanOrEqualAndUpperGreaterThanOrEqual(Double a, Double b); // where a==b
Run Code Online (Sandbox Code Playgroud) 我想我是在询问协变返回类型.我有一些生成的代码,我正在尝试扩展和使用.我们假设我有以下两个类:
public class SuperParent
{
public List<SuperChild> getList()
{
return new ArrayList<SuperChild>();
}
}
public class SuperChild
{
}
Run Code Online (Sandbox Code Playgroud)
现在,我想从这些中派生出新的类:
public class SubParent extends SuperParent
{
public List<SubChild> getList()
{
return new ArrayList<SubChild>();
}
}
public class SubChild extends SuperChild
{
}
Run Code Online (Sandbox Code Playgroud)
问题是,显然我不能覆盖getList()方法,因为返回类型不匹配,尽管两个类都在同一方向上扩展.谁能解释一下?
我正在寻找使用svg图像并解析/处理不同的路径以进行自定义转换。在Java中,最简单的方法是简单地提取路径数据?我正在查看apache xmlgraphics / batik包,但是如何返回路径类型和参数并不是很明显。有什么建议么?
我期望来自以下方面的例外:
LocalDate.parse("9/31/2018",DateTimeFormatter.ofPattern("M/d/yyyy"));
Run Code Online (Sandbox Code Playgroud)
但是相反,我得到了2018年9月30日!?别误会我的意思,它很聪明很不错,但是我已经期望Java的Date类的精度会更高……
谁能阐明为什么/为什么?这将弄乱我的测试。
java ×4
c# ×2
overloading ×2
spring ×2
angularjs ×1
batik ×1
covariance ×1
enums ×1
generics ×1
inheritance ×1
java-date ×1
jaxb ×1
jpql ×1
maven ×1
overriding ×1
plugins ×1
properties ×1
spring-data ×1
spring-el ×1
svg ×1
xpath ×1