小编Ben*_*n M的帖子

没有未定义的TypeScript Partial <T>类型

如何创建一个还挺 - Partial<T>类型,不允许undefined值?

这是一个例子:

interface MyType {
  foo: string
  bar?: number
}

const merge = (value1: MyType, value2: KindaPartial<MyType>): MyType => {
  return {...value1, ...value2};
}



const value = {
  foo: 'foo',
  bar: 42
}

merge(value, {});                          // should work
merge(value, { foo: 'bar' });              // should work
merge(value, { bar: undefined });          // should work
merge(value, { bar: 666 });                // should work
merge(value, { foo: '', bar: undefined }); // should work
merge(value, { …
Run Code Online (Sandbox Code Playgroud)

generics partial typescript

9
推荐指数
2
解决办法
1386
查看次数

如何在gwt-platform中使用GWT的编辑框架?

我正在使用gwt-platform并尝试实现GWT的编辑器框架.但是我没有在演示者中得到它.网络上有一些答案,说我必须以某种方式将EditorDriver注入Presenter,但我不知道如何做到这一点......

目前我尝试了这个没有成功:

public class MyPresenter extends Presenter<MyPresenter.MyView, MyPresenter.MyProxy> implements MyUiHandlers {
    public interface MyView extends View, HasUiHandlers<MyUiHandlers>, Editor<MyModel> {}

    @ProxyStandard
    @NameToken(NameTokens.myPage)
    @NoGatekeeper
    public interface MyProxy extends ProxyPlace<MyPresenter> {} 

    interface Driver extends SimpleBeanEditorDriver<MyModel, MyView> {}
    private Driver editorDriver;
    DispatchAsync dispatcher;

    @Inject
    public MyPresenter(EventBus eventBus, MyView view, MyProxy proxy, DispatchAsync dispatcher) {
        super(eventBus, view, proxy);
        getView().setUiHandlers(this);
        this.dispatcher = dispatcher;

        MyModel m = new MyModel();
        m.setId(1L);
        m.setUsername("username");
        m.setPassword("password");

        editorDriver = GWT.create(Driver.class);
        editorDriver.initialize(this.getView());
        editorDriver.edit(m);
    }

    ...
}
Run Code Online (Sandbox Code Playgroud)

如果我明确指定ViewImplementation,它可以工作,但这不是MVP应该工作的方式:

interface Driver extends SimpleBeanEditorDriver<MyModel, MyViewImpl> {} …
Run Code Online (Sandbox Code Playgroud)

gwt gwt-platform gwt-editors

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

如何通过GIN与UiBinder和Widgets一起使用注入?

我正在使用GWT 2.4与gwt-platform 0.7和gin 1.5.0.

我已经为我的GWT应用程序的动态(实时)翻译构建了一个库.因此,每个小部件都会在LocaleChangeEvent被触发时得到通知,然后让我TranslationDictionary获取要显示的新String.

小部件实际上看起来像这样:

public class LocaleAwareLabel extends Label implements LocaleChangeEventHandler {
    TranslationDictionary dictionary;
    String translationToken;

    public LocaleAwareLabel(TranslationDictionary dictionary, EventBus eventBus, String translationToken) {
        this.dictionary = dictionary;
        this.translationToken = translationToken;
        eventBus.addHandler(LocaleChangeEvent.TYPE, this);
        getCurrentTranslationFromDictionary();
    }

    public void getCurrentTranslationFromDictionary() {
        this.setText(dictionary.getTranslation(translationToken));
    }

    @Override
    public void onLocaleChange(LocaleChangeEvent event) {
        getCurrentTranslationFromDictionary();
    }
}
Run Code Online (Sandbox Code Playgroud)

正如你所看到的:我不能轻易地将这个小部件与UiBinder一起使用,在我注入的时刻EventBusTranslationDictionary我的View使用方式@UiField(provided=true)如下:

@UiField(provided=true)
LocaleAwareLabel myLabel;

@Inject
public MyView(TranslationDictionary dictionary, EventBus eventBus) {
    widget = uiBinder.createAndBindUi(this);

    myLabel = new …
Run Code Online (Sandbox Code Playgroud)

gwt gwt-gin dependency-injection uibinder

8
推荐指数
2
解决办法
5017
查看次数

多模块Maven项目中的Spring Security(在哪里放置DB auth,UserDetails等?)

目前我们有6个Maven模块:

  • webapp
  • security
  • core(提供数据库访问User)
  • common
  • module1
  • module2

我认为依赖树非常明显:

  • webapp 取决于一切
  • security 取决于核心
  • core 取决于共同点
  • common 什么都不依赖
  • module1 取决于核心和共同点
  • module2 取决于核心,module1和common

现在我想要一些BaseEntity:它应该有一个@PrePersist可以节省电流User.几乎每个实体都会使用它BaseEntity.这就是每个模块依赖的原因core.

而且因为一切都依赖于core,将这BaseEntity也放在core模块中似乎是合乎逻辑的.(即使我更喜欢使用common它,但由于依赖性,这似乎是不可能的).

现在出现问题:要设置当前用户,我必须使用访问权限SecurityContextHolder.getContext().getAuthentication().getPrincipal().但是有了这个,我会有一些不必要的依赖(或者我只是太挑剔了?).

如果我想要自定义实现,问题会变得更糟UserDetails.我应该把它放在哪里?core还是security?或者让User实体实施UserDetails是否常见?我不这么认为.问题出现了,因为在验证用户时,我必须UserDetailssecurity模块内创建对象.当我想要检索当前时,User我必须将getPrincipal()方法强制转换为自定义UserDetails类.

我真的很困惑如何松散耦合,但也实现了应用程序所需的一切.

我想到的最后一个想法是关于使用依赖注入,但我不知道它是否有效!?(在模块中有一个currentUserBean security,其他人都可以通过它获得它@Autowired MyCustomUserDetails)

所以请帮我把这些东西弄好!

谢谢! :)

spring dependencies spring-security maven multi-module

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

Angular 2组件:如何处理循环输入和输出

现在的情况:

我有一个parent和一个child组件.

parent初始化child使用它的数据@Input.child当用户使用编辑数据时,通知父母@Output.并且由于数据是不可变的,因此child必须将数据与该通知一起发送.

parent得到通知时,它将检查提交的数据是否有效,然后将其设置(这也将新值传播到其他一些子组件).

问题:

当在其中设置新数据时parent,它当然也会将其提供给child刚刚提交数据的组件.这将触发child's ngOnChanges,然后触发重新绘制UI.

一些背景:

parent有几个不同的child组件,它们都依赖于相同的myItem数据,可以编辑这些数据,然后通知parent更改.


这是代码的简化版本,应该会显示问题.

父组件:

template:
    <child [input]="myItem" (output)="onMyItemChange($event)">

code:
    ngOnInit() {
        this.myItem = getDataViaHTTP();
    }

    onMyItemChange($event) {
        if($event.myItem.isValid()) {
            this.myItem = $event.myItem;
        }
    }
Run Code Online (Sandbox Code Playgroud)

子组件:

template:
    <input [(ngModel)]="myItem.name" (ngModelChange)="modelChange($event)">

code:
    @Input() input;
    @Output() output = new EventEmitter();

    myItem; …
Run Code Online (Sandbox Code Playgroud)

immutability event-handling angular2-template angular

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

复杂应用程序的高性能 ACL 模式(RDBMS、图形数据库?)

我正在使用 Java/Spring 和至少 2 个不同的数据库构建一个相当复杂的 Web 应用程序:

  • 主数据的关系型数据库
  • MongoDB 用于文件(通过 GridFS)和其他数据 CLOB/JSON/等。

下一步是授权。简单的基于角色的授权是不够的,因为应该允许/禁止用户查看/修改不同的资源。虽然我想到了 ACL。

最常见的简单 ACL 表可能如下所示:

TABLE  | FIELDS
-------+--------------
class  | id, className
object | id, class_id, objectId
acl    | id, object_id, user_id, permissionBitMask (crud)
Run Code Online (Sandbox Code Playgroud)

但不幸的是,这不足以满足我的需求:(

我也需要:

  • 角色
    • 每个用户可以有多个角色,并且
    • ACL 条目也可以属于一个角色
  • 更多权限
    • 例如:每个项目可以有多个任务不能修改项目详细信息的用户为该项目创建新任务。所以必须有一个单独的许可。
  • 不同类型的 ObjectId
    • RDBMS 表将使用 UUID 代理键(所以至少我不必在这里处理复合键)
    • 但是 MongoDB 当然使用它自己的 ObjectId
    • 此外,我将在代码中包含一些静态资源,这些资源也必须受到访问限制。
  • 父对象继承权限

如果我结合所有这些方面,我会得到以下表格结构:

TABLE          | FIELDS
---------------+--------------
class          | id, className
object         | id, class_id, …
Run Code Online (Sandbox Code Playgroud)

permissions rdbms acl authorization neo4j

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

为地图和/或嵌套对象自定义Spring @RequestParam反序列化

@RestController
class MyController {
     @RequestMapping(...)
     public void test(Container container) { ... }
}
Run Code Online (Sandbox Code Playgroud)

Spring默认使用Dot-Notation反序列化嵌套的@RequestParam:

class Container {
    A a;
}

class A {
    String val;
}
Run Code Online (Sandbox Code Playgroud)

适用于:

http://.../myController?a.val=foo
Run Code Online (Sandbox Code Playgroud)

但对于地图,它使用方形括号表示法:

class Container {
    Map<String, String> a;
}
Run Code Online (Sandbox Code Playgroud)

适用于:

http://.../myController?a[val]=foo
Run Code Online (Sandbox Code Playgroud)

当使用JavaScript时,HashMap和嵌套对象之间当然没有区别,因此所有内容都将使用Dots Square-Brackets进行序列化.


题:

如何/我在哪里可以告诉Spring(或Spring启动,如果这更容易)使用点符号(或方括号中)为两个,嵌套对象地图?

或者,有什么理由说Spring会对这些类型产生影响吗?

spring spring-mvc http-request-parameters spring-boot spring-4

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

Angular2路由器:无需导航即可获取URL路由

我想routerLink基于Data路由器中的一些显示/隐藏s .该指令已经完成,但我错过了最重要的部分......

例如,我有以下路由器配置(省略组件):

[
  { path: '', children: [
    { path: 'foo', children: [
      { path: 'bar', data: { requiredPermissions: ['a', 'b'] } }
    ]}
  ]},
  { path: 'baz', data: { requiredPermissions: ['c'] }, children: [
    { path: ':id' }
  ]}
]
Run Code Online (Sandbox Code Playgroud)

现在我想问问RouterRoute,如果将用于routerLink/foo/bar/baz/123.

我查看了Router源代码(https://github.com/angular/angular/blob/master/modules/%40angular/router/src/router.ts),但找不到一些简单的方法来执行此操作.特别是它如何处理这些:id变量.

当然,我可以迭代Router.config,越走越深.但是后来我必须解析那些变量,正则表达式等等.必须有一种更简单的方法,因为角度路由器也必须在内部完成所有这些工作.

你有什么想法/解决方案吗?

angular2-routing angular2-router angular2-router3 angular

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

Spring Cloud Security JWT:使用配置服务器/密钥轮换分发公钥

如何在Spring Cloud环境中管理用于签署/验证JWT的私钥/公钥?

问题":

目前我生成一个密钥对.然后将Private + Public Key复制到我的auth-server应用程序.并将公钥复制到每个资源服务器.

当我现在想要实现"密钥轮换"时,我必须以某种方式为每个服务填充新密钥.


想法:

也许我可以用它spring-cloud-config-server来存储和分发Key Pairs?

配置服务器已提供数据库登录凭据.那么为什么不在那里存储更敏感的信息呢?


问题(S):

如果这是要走的路:你将如何实现密钥对分配spring-cloud-config-server

你有任何安全问题吗?

你是怎么解决这个问题的?我想有更好的解决方案.


编辑:

也许有一些解决方案使用Spring Oauth的security.oauth2.resource.jwt.keyUriJWK属性?

spring jwt key-pair spring-cloud spring-cloud-config

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

带有空值的光标分页(上一个/下一个)

我有一个用 MySQL(版本 8.0)实现的游标分页,只要不null涉及任何值,它就可以正常工作。

这是我的示例数据(id是随机 UUID,date是日期,time是时间):

id | date       | time
--------------------------
68 | 2017-10-28 | 22:00:00
d3 | 2017-11-03 | null
dd | 2017-11-03 | 21:45:00
62 | 2017-11-04 | 14:00:00
a1 | 2017-11-04 | 19:40:00
Run Code Online (Sandbox Code Playgroud)

cursor使用的总是由所有三列组成。

我使用此查询来获取一个结果(在 之后cursor):

id | date       | time
--------------------------
68 | 2017-10-28 | 22:00:00
d3 | 2017-11-03 | null
dd | 2017-11-03 | 21:45:00
62 | 2017-11-04 | 14:00:00
a1 …
Run Code Online (Sandbox Code Playgroud)

mysql sql pagination

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