我想使用流畅的api Optional并应用两个Consumers.
我在梦想这样的事情:
Optional.ofNullable(key)
.map(Person::get)
.ifPresent(this::printName)
.ifPresent(this::printAddress); // not compiling, because ifPresent is void
Run Code Online (Sandbox Code Playgroud)
我该如何申请几个Consumers到的Optional?
我有一个实体类User.我想添加一些属性,但要让它们可以为空.
JPA中使用的注释是什么?
我在Google App Engine中使用JPA.
我的实体类看起来像这样:
public class Student {
private int grade;
// other fields and methods
}
Run Code Online (Sandbox Code Playgroud)
我这样使用它:
List<Student> students = ...;
Run Code Online (Sandbox Code Playgroud)
我如何排序students的grade,考虑到这是一个私人领域?
我正在寻找一种简洁的方法来过滤掉特定索引中List中的项目.我的示例输入如下所示:
List<Double> originalList = Arrays.asList(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
List<Integer> filterIndexes = Arrays.asList(2, 4, 6, 8);
Run Code Online (Sandbox Code Playgroud)
我想筛选出的索引项2,4,6,8.我有一个for循环跳过与索引匹配的项目,但我希望有一种简单的方法可以使用流来完成.最终结果如下:
List<Double> filteredList = Arrays.asList(0.0, 1.0, 3.0, 5.0, 7.0, 9.0, 10.0);
Run Code Online (Sandbox Code Playgroud) 我正在使用SonarQube 5.6.3.如何将SonarQube分析详细信息报告创建为PDF表单,Excel报告或html格式的报告?
似乎没有插件可用于此.
我无法使用以下配置生成html文件:
sonar.issuesReport.html.enable = true
sonar.issuesReport.html.location = c:\
sonar.issuesReport.html.name = sample
Run Code Online (Sandbox Code Playgroud)
如何从SonarQube导出这些详细信息?
在定义新的Spring引导REST资源时,我倾向于忘记为其url模式创建spring安全配置.
默认情况下,如何拒绝访问所有URL,并且只允许访问明确配置的URL模式?(我.hasRole用来允许访问)我想避免尽可能多的意外安全漏洞.
比方说,我有三个REST资源:/jobs,/desks和/salary.我当前的代码可能如下所示:
http.authorizeRequests()
.antMatchers(HttpMethod.GET, "/jobs")
.hasRole("my_user")
.antMatchers(HttpMethod.GET, "/desks")
.hasRole("my_user");
Run Code Online (Sandbox Code Playgroud)
但目前,/salary每个人都可以访问url (因为它尚未配置)!
我使用spring boot在我们的数据库中通过JPA存储复杂的json结构.
json结构的根代表一个"House"对象."House"对象包含几个"Furnitures".例如:
House ID: 4711
|- Furniture: ID 4712 (with confidential information)
Run Code Online (Sandbox Code Playgroud)
用户对某些房屋及其所有"家具"具有读/写权限.
我的问题是,通过REST-API,用户可以"窃取"来自其他房屋的家具,如果他知道他们的主要钥匙; 请求像这样一个:
POST http://localhost:8080/house
{
houseId: 99991337,
furnitures: [{
furnitureId: 4712,
...
}]
}
Run Code Online (Sandbox Code Playgroud)
这导致:
House ID: 4711
|- empty!
House ID: 99991337
|- Furniture 4712 (with confidential information)
Run Code Online (Sandbox Code Playgroud)
虽然用户没有获得House 4711的许可,但他将House 4711与家具4712"取消关联",而是将其与House 99991337联系起来.
我如何禁止改变家具之家?
在JPA-Entities中,存在从房屋到家具的双向OneToMany关系.我想可能在数据库中搜索任何传入请求的家具,检查所有这些请求的所有权限.但我更愿意只需要检查众议院的许可(因为在现实生活中,我有更多的实体,如家具)
我正在迁移一些 Java 10 之前的代码,我想知道IntelliJ是否提供了一种自动重构代码的方法,以尽可能用var替换使用实际类型的变量声明。
该代码充满了诸如以下内容:
String status = "empty";
BigDecimal interest = BigDecimal.ZERO;
List<Future<Boolean>> results = es.invokeAll(tasks);
LocalDate start = LocalDate.of(2020, 1, 1);
Run Code Online (Sandbox Code Playgroud)
我更愿意:
var status = "empty";
var interest = BigDecimal.ZERO;
var results = es.invokeAll(tasks);
var start = LocalDate.of(2020, 1, 1);
Run Code Online (Sandbox Code Playgroud)
我已经查看了 IntelliJ 的设置(代码样式/检查),但找不到任何内容。
每当我使用SonarQube项目属性创建一个新项目时,我都会收到此错误:
04:13:57.939 DEBUG: Upload report
04:14:11.533 DEBUG: POST 500 sonarserverurl/api/ce/submit?projectKey=Somename&projectName=Somename | time=13580ms
04:14:11.540 INFO: ------------------------------------------------------------------------
04:14:11.540 INFO: EXECUTION FAILURE
04:14:11.540 INFO: ------------------------------------------------------------------------
04:14:11.540 INFO: Total time: 2:25.443s
04:14:11.639 INFO: Final Memory: 56M/647M
04:14:11.639 INFO: ------------------------------------------------------------------------
04:14:11.639 ERROR: Error during SonarQube Scanner execution
org.sonarqube.ws.client.HttpException: Error 500 on sonarserver:9000/api/ce/submit?projectKey=Some name&projectName=Some name* : {"errors":[{"msg":"An error has occurred. Please contact your administrator"}]}
at org.sonarqube.ws.client.BaseResponse.failIfNotSuccessful(BaseResponse.java:36)
at org.sonar.scanner.bootstrap.ScannerWsClient.failIfUnauthorized(ScannerWsClient.java:106)
at org.sonar.scanner.bootstrap.ScannerWsClient.call(ScannerWsClient.java:75)
at org.sonar.scanner.report.ReportPublisher.upload(ReportPublisher.java:177)
at org.sonar.scanner.report.ReportPublisher.execute(ReportPublisher.java:131)
at org.sonar.scanner.phases.PublishPhaseExecutor.publishReportJob(PublishPhaseExecutor.java:71)
at org.sonar.scanner.phases.PublishPhaseExecutor.executeOnRoot(PublishPhaseExecutor.java:53)
at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:79)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:175)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:143)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:128) …Run Code Online (Sandbox Code Playgroud) 我经常重新定义交互式以在历史记录中进行微小的更改(例如删除空白行或编辑一行).在大多数情况下,这些变化是基于一些同行评审.
起初我做这样的改变:
git rebase --interactive 83bbeb27fcb1b5e164318fa17c55b7a38e5d3c9d~
# replace "pick" by "edit" on the first line
# modify code
git commit --all --amend --no-edit
git rebase --continue
Run Code Online (Sandbox Code Playgroud)
如果以下提交之一中存在合并冲突,我将解决它们并执行此操作:
git rebase --continue
# the commit message is shown, but does not have to be changed, so I just save and exit the editor
git rebase --continue
# the commit message is shown, but does not have to be changed, so I just save and exit the editor
git rebase --continue
# the …Run Code Online (Sandbox Code Playgroud) java ×7
jpa ×2
sonarqube ×2
spring ×2
spring-boot ×2
command-line ×1
git ×1
java-8 ×1
java-stream ×1
list ×1
macos ×1
oop ×1
optional ×1
sonar-runner ×1
sorting ×1