原始代码是
if(object==null){
throw new CustomException(ErrorEnum.OBJECT_NULL)
}
Run Code Online (Sandbox Code Playgroud)
现在我想Optional用来处理NullPointerException. 像这样
Optional.ofNullable(object).orElseThrow(()->{throw new CustomException(ErrorEnum.OBJECT_NULL);}
Run Code Online (Sandbox Code Playgroud)
但是这样做会使代码比原始代码长得多。也许我应该使用第一种方法来解决问题?
我按照官方文档安装了gitlab。
sudo docker run --detach \
--hostname git.stupidpz.com \
--publish 8443:443 --publish 880:80 --publish 822:22 \
--name gitlab \
--restart always \
--volume $GITLAB_HOME/config:/etc/gitlab \
--volume $GITLAB_HOME/logs:/var/log/gitlab \
--volume $GITLAB_HOME/data:/var/opt/gitlab \
--shm-size 256m \
gitlab/gitlab-ee:latest
Run Code Online (Sandbox Code Playgroud)
现在我想使用Nginx(自己安装的)来反向代理gitlab,而不是gitlab容器自带的nginx。
根据官方文档我添加了一些代码gitlab.rb
# Define the external url
external_url 'http://git.stupidpz.com'
# Disable the built-in nginx
nginx['enable'] = false
# Disable the built-in puma
puma['enable'] = false
# Set the internal API URL
gitlab_rails['internal_api_url'] = 'http://git.stupidpz.com'
# Define the web …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Spring Boot,Spring Security 4,Thymeleaf。并且如果用户具有“ admin”角色或其他任何角色。应该显示html块。但是现在它始终显示在页面上。这是我的html
<html lang="en" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<div sec:authorize="hasRole('ROLE_GUEST')">
<p class="bg-info">guest</p>
</div>
<div sec:authorize="hasRole('ROLE_ADMIN')">
<p class="bg-info">you can see this if you have permission to acess role_admin</p>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的pom.xml,我确实添加了thymeleaf-extras-springsecurity4。还尝试了thymeleaf-extras-springsecurity3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zhongdihang.resp</groupId>
<artifactId>resp-parent</artifactId>
<version>1.0.0</version>
<relativePath>../resp-parent</relativePath>
</parent>
<artifactId>resp-serve</artifactId>
<packaging>war</packaging>
<name>Real estate sharing platform serve</name>
<description>Real estate sharing platform serve</description>
<dependencies>
<!-- Compile -->
<dependency>
<groupId>com.zhongdihang.resp</groupId>
<artifactId>resp</artifactId>
</dependency>
<dependency>
<groupId>com.zhongdihang.resp</groupId>
<artifactId>resp-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId> …Run Code Online (Sandbox Code Playgroud) 我希望获得一些对象的属性,List<Object>并将它们放入List<Map<String,Object>>使用java8的lambda中.在Java7中,我会以这种方式编写.为了使这个可读,我想用Java8的Lambda以另一种方式翻译它.
List<HouseModel> _house = new ArrayList<>();
List<Map<String, String>> list = new ArrayList<>();
Map<String, String> map = new HashMap<>(2);
for (HouseModel h : _house) {
map.put("address", h.getAddress());
map.put("number", h.getHouseNum());
list.add(map);
}
Run Code Online (Sandbox Code Playgroud) for (GroupEntity groupEntity : groups) {
// find roles belongs to group
Collection<RoleEntity> groupRoles = groupEntity.getRoles();
for (RoleEntity roleEntity : groupRoles) {
if (roleEntity.getType() == RoleType.MODULE) {
ModuleEntity module = roleEntity.getModule();
if (!modules.contains(module)) {
// prevent duplicate module
modules.add(module);
}
} else if (roleEntity.getType() == RoleType.OUTLINE) {
OutlineEntity outline = roleEntity.getOutline();
//prevent duplicate outline
if (!outlines.contains(outline)) {
outlines.add(outline);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望得到与Lambda相同的结果.我试过但它反复出现List<List<RoleEntity>>.
List<List<RoleEntity>> roles= groups.stream().map(g->g.getRoles().stream()
.filter(distinctByKey(RoleEntity::getId))
.collect(Collectors.toList())
.stream().filter(r->RoleType.MODULE.equals(r.getType()))
.collect(Collectors.toList())
).collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
我知道lambda对于编码器来说是一个了不起的想法.但是学习它似乎并不那么容易.希望有人可以帮我解决问题.谢谢!:XD