在Tomcat的官方页面中,它说Tomcat 7支持Java 8.如果我下载它并使用Java 8运行它可以工作.
但是,在Openshift上是Tomcat 7(JBoss EWS 2.0).在这个网页中,它说EWS 2.0 不支持Java 8.如果我将我的Java 8应用程序部署到Openshift(Tomcat 7),它就无法运行.
为什么?
我尝试在Openshift上使用Tomcat 7安装Java 8:https://stackoverflow.com/a/23895161/2442133 但它并不适合我.我有错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping':
Initialization of bean failed; nested exception is
org.springframework.beans.factory.CannotLoadBeanClassException: Error loading
class [pl.xxx.controller.HomeController] for bean with name 'homeController'
defined in file [/var/lib/openshift/xxx/app-
root/runtime/dependencies/jbossews/webapps/web1/WEB-
INF/classes/xxx/controller/HomeController.class]: problem with class file or
dependent class; nested exception is java.lang.UnsupportedClassVersionError:
xxx/controller/HomeController : Unsupported major.minor version 52.0 (unable to
load class xxx.controller.HomeController)
Run Code Online (Sandbox Code Playgroud)
Unsupported …
我有很长的 JSON 文件,例如:
{
"a": {
"b": {
"c": "keyC"
}
}
}
Run Code Online (Sandbox Code Playgroud)
和路径:a.b.c
如何使用路径在 JSON 中搜索(转到行)?
问题类似于如何在 IntelliJ IDEA 中复制 JSON 中的路径?但反过来(JSON 中放置的路径而不是 JSON 中放置的路径)。
我正在开发使用 D3.js 来显示一些可视化的应用程序。如何在 GitHub 上显示 HTML 文件(使用 JS)的预览?我需要每个提交(历史)的演示,而不仅仅是最新版本。
我使用捆绑的 JSON 数据和来自 CDN 的链接 D3.js 库将应用程序的静态版本生成为 HTML+JS,因此我只需要提供 HTML+JS 服务。没有后端。
我的第一个想法是使用 GitHub Pages (这是流行的答案#1、#2)。这很好,但是这样我就可以仅显示最新版本的演示(如果我为分支docs上的目录设置 gh-pages,则为最新提交master)或仅针对一个特定版本(如果我为gh-pages分支设置 gh-pages 并向其推送某个版本) )。
我需要为存储库中的所有提交显示演示(预览 HTML)。我希望能够看到以前版本的应用程序的演示(预览以前的提交)。
我可以制作运行 D3.js 应用程序的屏幕截图,并将图像附加到存储库并在README.md. 当有人打开以前的提交时,他会看到应用程序的以前版本。这就是我要的。
但对于静态图像,我失去了 D3.js 的优势。我的应用程序是动态的(您可以缩放、单击图表、选择要显示的数据、显示工具提示等)。
我发现(#1,#2)服务可以直接从 GitHub 提供 HTML 文件:
有了这个,我可以链接到特定文件(甚至是特定版本的文件!就是这样!)并通过 HTMLPreview/RawGit 代理来显示预览。
但我对此有两个问题:
1. RawGit 的作者说我不应该使用这个工具来创建公共演示(我只是想做!):
不要在示例代码或公共演示中使用开发 URL,因为人们经常复制并粘贴该代码并在生产应用程序中使用它,而没有意识到他们需要更改 URL。然后他们向 RawGit …
我用角度分量(从第一示例这个).当我在组件中绑定对象时,它可以在模板中访问,但不在控制器中.
JS:
function HeroDetailController() {
console.log("Here I want to use hero.name: ");
console.log(hero.name); // I want to use binding object in controller, but doesn't work
}
angular.module('heroApp').component('heroDetail', {
templateUrl: 'heroDetail.html',
controller: HeroDetailController,
controllerAs: 'ctrl',
bindings: {
hero: '='
}
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<hero-detail hero="ctrl.hero"></hero-detail>
Run Code Online (Sandbox Code Playgroud)
模板html(这里有效):
<span>Name: {{ctrl.hero.name}}</span>
Run Code Online (Sandbox Code Playgroud)
错误:
ReferenceError:未定义英雄
Plunker:https://plnkr.co/edit/U9CJLs6jgrlsZH6tUdr0
我有一个方法,我想添加特定的日志记录:
@Slf4j
@Service
public class SomethingService {
public void doSomething(Something data, String comment, Integer limit) {
Long id = saveSomethingToDatabase(data, comment);
boolean sentNotification = doSomething(id);
// ...
// Log what you done.
// Variables that always have important data: data.getName(), id
// Variables that are optional: sentNotification, comment, limit
// (optional means they aren't mandatory, rarely contains essential data, often null, false or empty string).
}
}
Run Code Online (Sandbox Code Playgroud)
我可以简单地记录所有:
log.info("Done something '{}' and saved (id {}, sentNotification={}) with comment '{}' and …Run Code Online (Sandbox Code Playgroud) 当我根据条件从许多表中获取列并且由于使用了聚合函数CASE而必须使用此名称时,如何保留原始列名称?GROUP BY我需要它来创建VIEW正确的列名称。我使用 PostgreSQL。
我有三张桌子:
create table first
(
id bigserial primary key,
field varchar(255) not null
);
create table second
(
id bigserial primary key,
field varchar(255) not null,
first_id bigint constraint second_first_id references first
);
create table values
(
id bigserial primary key,
value numeric,
first_id bigint constraint value_first_id references first
);
Run Code Online (Sandbox Code Playgroud)
一些输入数据:
insert into first (field) values ('aaa');
insert into first (field) values ('bbb');
insert into second (field, first_id) values ('ggg', …Run Code Online (Sandbox Code Playgroud) 我有两节课。模型:
@Data
public class ExampleModel {
private String someField;
private String fieldInModel;
}
Run Code Online (Sandbox Code Playgroud)
和 DTO:
@Data
public class ExampleDto {
private String someField;
private String fieldInDto;
}
Run Code Online (Sandbox Code Playgroud)
我想配置简单的映射器(使用不同的字段名称):
@Mapper(componentModel = "spring")
public interface ExampleMapper {
@Mapping(target = "fieldInModel", source = "fieldInDto")
ExampleModel mapToExample(ExampleDto exampleDto);
}
Run Code Online (Sandbox Code Playgroud)
我的项目是一个简单的 Spring Initializr,我在其中添加了 Lombok 和 MapStruct 的配置:
...
<properties>
<java.version>11</java.version>
<mapstruct.version>1.4.1.Final</mapstruct.version>
<lombok.version>1.18.16</lombok.version>
</properties>
<dependencies>
...
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> …Run Code Online (Sandbox Code Playgroud) 我有一个字符串,我想将其解析为布尔值。如果它不包含true或false字符串,它应该返回默认值(true在我的例子中)。
"true" -> true
"false" -> false
"something" -> true
Run Code Online (Sandbox Code Playgroud)
我正在寻找 Java 方法或一些 util(Apache Commons 或 Guava)。
我无法使用Java方法Boolean.parseBoolean,因为它没有带默认值的参数(默认值始终是false):
System.out.println(Boolean.parseBoolean("true")); // true
System.out.println(Boolean.parseBoolean("false")); // false
System.out.println(Boolean.parseBoolean("something")); // false instead of true
Run Code Online (Sandbox Code Playgroud)
与 Apache Commons 相同BooleanUtils.toBoolean:
System.out.println(BooleanUtils.toBoolean("true")); // true
System.out.println(BooleanUtils.toBoolean("false")); // false
System.out.println(BooleanUtils.toBoolean("something")); // false instead of true
Run Code Online (Sandbox Code Playgroud)
我可以写我自己的方法:
private static Boolean toBoolean(String value, boolean defaultValue) {
return Optional.ofNullable(BooleanUtils.toBooleanObject(value))
.orElse(defaultValue);
}
Run Code Online (Sandbox Code Playgroud)
并使用它:
System.out.println(toBoolean("true", true)); // true
System.out.println(toBoolean("false", true)); // false …Run Code Online (Sandbox Code Playgroud)