小编Ric*_*ick的帖子

Spring Data R2DBC PostgreSQL 不使用 UUID @Id 保存新记录

我有一个简单的实体,由两个 UUID 组成:

\n
@Table("library")\npublic class LibraryDao {\n    @Id\n    private UUID id;\n    @NonNull\n    private UUID ownerId;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我在 PostgreSQL 中有一个对应的表:

\n
CREATE TABLE IF NOT EXISTS library (id UUID PRIMARY KEY, owner_id UUID NOT NULL);\n
Run Code Online (Sandbox Code Playgroud)\n

我正在使用正确的 R2DBC 驱动程序(io.r2dbc:r2dbc-postgresqlorg.postgresql:postgresql)。

\n

至此,一切正常。我的应用程序运行。但是\xe2\x80\xa6

\n

因为 PostgreSQL 至少根据文档 \xe2\x80\x93 没有 UUID 自动生成功能,所以我在创建新实例时设置了 id LibraryDao

\n

但是,当我save在存储库中调用该方法时,出现异常:Failed to update table [library]. Row with Id [0ed4d7c0-871a-4473-8997-4c9c1ec67a00] does not exist.

\n

似乎save被解释为,如果它不存在则update不会回退。insert

\n …

java postgresql spring-data-r2dbc

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

CSS on:专注于contenteditable的子对象

我试图检测focus元素的子元素,以contenteditable实现纯CSS样式。(我知道我可以使用JS来检测到这一点,添加一个额外的类并以这种方式进行操作,但这太漫长了。)

基本上,我有一些类似的东西:

<div contenteditable="true">
  Some text <span class="edit">that</span> goes here.
</div>
Run Code Online (Sandbox Code Playgroud)

我按照以下方式尝试了CSS:

.edit:focus {
  color: #FF0000;
}
Run Code Online (Sandbox Code Playgroud)

我希望span当插入符插入时改变颜色,但显然焦点仅应用于的div设置contenteditable,而不应用于其任何子级。我曾尝试对施加一秒钟contenteditable的时间span,但除了采取一种非常草率的方法外,它还是无法正常工作。

这个问题有方法解决吗?

css contenteditable

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

使用 isPresent() 从Optional内部获取值

我有一个User相关的限时Roles。我想知道 a 是否User有特定的UserRole 且未过期。我可以将用户的角色转换为流,filter()它和findFirst(),给我一个Optional.

角色

public class Role {
    private UserRole role;
    private Date expiry;
    
    public boolean isUnexpired () {
        return (expiry == null) ? true : expiry.after(new Date());
    }
}
Run Code Online (Sandbox Code Playgroud)

用户

public class User {
  //...
  private Collection<Role> roles

  public boolean hasRole (UserRole userRole) {
    return roles.stream()
      .filter(r -> r.getRole().equals(userRole))
      .findFirst()
      .ifPresent(ur -> {  /* ... herein the problem ... */ ur.isUnexpired(); } );
  } …
Run Code Online (Sandbox Code Playgroud)

java option-type

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

@EnableAuthorizationServer 注解的导入路径是什么

我正在尝试理解 Spring 授权服务器。

\n

遵循各种教程和原始文档,几乎是配置依赖项 \xe2\x80\x93 后的第一步

\n
dependencies {\n    implementation 'org.springframework.boot:spring-boot-starter-webflux'\n    implementation 'org.springframework.boot:spring-boot-starter-security'\n    implementation 'org.springframework.security:spring-security-oauth2-authorization-server:0.2.1'\n//  other db/test stuff\n}\n
Run Code Online (Sandbox Code Playgroud)\n

@EnableAuthorizationServer\xe2\x80\x93 是为主类添加注解。

\n

除了我的 IDE (NetBeans) 没有从导入中得知它指的是什么。

\n

那么:导入路径应该用于什么@EnableAuthorizationServer?(而且,从逻辑上讲,是否还需要一些其他依赖项才能识别它?)

\n

java spring oauth spring-security

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