小编sch*_*obe的帖子

如何在抽象超类中定义常量/最终变量,但是在子类中分配它们?

我有一个抽象类,我想声明最终变量.

但是,我想只在我的子类的构造函数中为这些变量赋值.

显然,这是不可能的,因为所有"最终字段都必须初始化".我不明白为什么,因为无论如何都不可能实例化一个抽象类.

我想拥有的是这样的:

abstract class BaseClass {
    protected final int a;
}

class SubClass extends BaseClass {
    public SubClass() {
        a = 6;
    }
}
Run Code Online (Sandbox Code Playgroud)

我想象一下在实现接口时类似于方法的东西.然后你也被迫在(子)类中实现方法.

java

12
推荐指数
1
解决办法
6240
查看次数

Springdoc OpenAPI ui 不支持“位置”中的上下文路径

设置:

springdoc-openapi-ui在一个简单的 spring-boot 项目中使用1.4.0 版本(通过 Maven)中的 Java 库,没有任何自定义。

Swagger 页面在https://my-url.com/my-context-path/swagger-ui/index.html下生成

https://my-url.com/my-context-path/v3/api-docs/下的 api-docs

这两个都有效,我可以联系到他们。到现在为止还挺好!

现在的问题:

当简单地导航到https://my-url.com/my-context-path/swagger-ui.html 时,我得到一个 HTTP 状态 302 和一个location在响应头中设置的属性,它应该将我重定向到 swagger 页面从上面(我假设)。

但是,location属性中的 URL缺少上下文路径!它看起来像这样:https : //my-url.com/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config

它重定向到一个不存在的页面,我收到 404 错误代码。请注意,configUrl 似乎也缺少上下文路径。

任何想法为什么会发生这种情况以及如何解决?

这个 Github 问题似乎是同样的问题,但最后声明问题已解决:https : //github.com/springdoc/springdoc-openapi/issues/37,这是针对比我更早的版本。

swagger swagger-ui springdoc springdoc-ui springdoc-openapi-ui

5
推荐指数
2
解决办法
3906
查看次数

导出到可运行的JAR后找不到资源文件

我有一个看起来像这样的项目结构:

Tester  
\-- src  
    |-- hello.java  
    \-- vocabulary.csv
Run Code Online (Sandbox Code Playgroud)

我使用getResource加载csv文件:

url = this.getClass().getResource("vocabulary.csv");
System.out.println(url.getPath());
new FileReader(url.getPath());
Run Code Online (Sandbox Code Playgroud)

该程序完全正常,直到我将项目导出到可运行的jar文件.即使URL仍然有效(他打印路径而不是null),控制台显示:

jar:file:/home/malte/Desktop/vocs.jar!/main/vocabulary.csv
Exception in thread "main" java.io.FileNotFoundException: file:/home/malte/Desktop/vocs.jar!/main/vocabulary.csv (No such file or directory)
Run Code Online (Sandbox Code Playgroud)

你能解释一下为什么会发生这种情况以及如何解决这个问题吗?

PS我使用Xtend而不是纯Java

java xtend

4
推荐指数
1
解决办法
1万
查看次数

在 Eclipse 中,Source -> Format 在“Maven Pom Editor”中被禁用

pom.xml当使用“Maven Pom Editor”在 Eclipse 中打开并切换到选项卡时pom.xml,我无法格式化该文件。

点击Ctrl+Shift+F完全未格式化的文件不会执行任何操作。通过上下文菜单时Source -> FormatFormat选项被禁用。

当我以 a 格式打开文件时XML Editor,格式化工作正常。

知道为什么会出现这种情况吗?


我尝试了EMBEDDED Maven外部版本3.5.2

蚀:

Eclipse IDE for Java Developers
Version: Oxygen.2 Release (4.7.2)
Build id: 20171218-0600

m2e Plugin 1.8.2
Run Code Online (Sandbox Code Playgroud)

编辑[已解决]:

我在包资源管理器中右键单击该文件。在那里,源 -> 格式已启用。单击它会导致异常:

java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 2
    at org.eclipse.wst.sse.core.internal.text.TextRegionListImpl.get(TextRegionListImpl.java:147)
    at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatWithinTag(DefaultXMLPartitionFormatter.java:886)
    at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatStartTag(DefaultXMLPartitionFormatter.java:543)
    at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatRegion(DefaultXMLPartitionFormatter.java:448)
    at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatStartTag(DefaultXMLPartitionFormatter.java:564)
    at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatRegion(DefaultXMLPartitionFormatter.java:448)
    at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatStartTag(DefaultXMLPartitionFormatter.java:564)
    at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatRegion(DefaultXMLPartitionFormatter.java:448)
    at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatStartTag(DefaultXMLPartitionFormatter.java:564)
    at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatRegion(DefaultXMLPartitionFormatter.java:448)
    at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatStartTag(DefaultXMLPartitionFormatter.java:564)
    at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatRegion(DefaultXMLPartitionFormatter.java:448) …
Run Code Online (Sandbox Code Playgroud)

eclipse m2eclipse maven m2e

4
推荐指数
1
解决办法
3108
查看次数

如何在 panelGrid 中插入条件行,同时保持行简洁?

我有h:panelGrid两列和多行:

<h:panelGrid columns="2">
    <p:outputLabel for="attr1" value="#{messages.attr1}" />
    <p:inputText id="attr1" value="#{viewBean.attr1}" />
    <p:outputLabel for="attr2" value="#{messages.attr2}" />
    <p:inputText id="attr2" value="#{viewBean.attr2}">
    <p:outputLabel for="attr3" value="#{messages.attr3}" />
    <p:inputText id="attr3" value="#{viewBean.attr3}" />
</h:panelGrid>
Run Code Online (Sandbox Code Playgroud)

现在,某些行只能有条件地出现。在示例中,这可能是 attr2 和 attr3。当我围绕它们构建一个<ui:fragment />条件渲染时(见下文),但是 jsf 尝试将整个块放入一个<td />表格单元格元素中。

<h:panelGrid columns="2">
    <p:outputLabel for="attr1" value="#{messages.attr1}" />
    <p:inputText id="attr1" value="#{viewBean.attr1}" />
    <ui:fragment rendered="#{viewBean.myCondition}">
        <p:outputLabel for="attr2" value="#{messages.attr2}" />
        <p:inputText id="attr2" value="#{viewBean.attr2}">
        <p:outputLabel for="attr3" value="#{messages.attr3}" />
        <p:inputText id="attr3" value="#{viewBean.attr3}" />
    </ui:fragment>
</h:panelGrid>
Run Code Online (Sandbox Code Playgroud)

另一种选择是创建两个 panelGrid。一个用于第一个块,一个用于第二个块:

<h:panelGrid columns="2">
    <p:outputLabel for="attr1" value="#{messages.attr1}" />
    <p:inputText id="attr1" …
Run Code Online (Sandbox Code Playgroud)

jsf

2
推荐指数
1
解决办法
1489
查看次数

如何重置到给定 git 提交之前的状态?

我有一个包含数百个提交的大型存储库。

给出的是历史深处某个特定提交的哈希值,其中某些内容已得到修复。我知道我可以通过使用恢复到该提交

git reset 56e05fced214c44a37759efa2dfc25a65d8ae98d
Run Code Online (Sandbox Code Playgroud)

但是,我想要应用修复之前的状态,即之前的一次提交。

(现在,在 SVN 中,我只需恢复到以前的修订号,但我知道使用 GIT 及其所有分布式特性,这并不那么容易)。

我怎样才能做到这一点?

git

1
推荐指数
1
解决办法
1291
查看次数