如何创建一个还挺 - 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) 我正在使用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 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一起使用,在我注入的时刻EventBus和 TranslationDictionary我的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) 目前我们有6个Maven模块:
webappsecuritycore(提供数据库访问User)commonmodule1module2我认为依赖树非常明显:
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是否常见?我不这么认为.问题出现了,因为在验证用户时,我必须UserDetails在security模块内创建对象.当我想要检索当前时,User我必须将getPrincipal()方法强制转换为自定义UserDetails类.
我真的很困惑如何松散耦合,但也实现了应用程序所需的一切.
我想到的最后一个想法是关于使用依赖注入,但我不知道它是否有效!?(在模块中有一个currentUserBean security,其他人都可以通过它获得它@Autowired MyCustomUserDetails)
所以请帮我把这些东西弄好!
谢谢! :)
现在的情况:
我有一个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) 我正在使用 Java/Spring 和至少 2 个不同的数据库构建一个相当复杂的 Web 应用程序:
下一步是授权。简单的基于角色的授权是不够的,因为应该允许/禁止用户查看/修改不同的资源。虽然我想到了 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)
但不幸的是,这不足以满足我的需求:(。
我也需要:
如果我结合所有这些方面,我会得到以下表格结构:
TABLE | FIELDS
---------------+--------------
class | id, className
object | id, class_id, …Run Code Online (Sandbox Code Playgroud) @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
我想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)
现在我想问问Router的Route,如果将用于routerLink为/foo/bar或/baz/123.
我查看了Router源代码(https://github.com/angular/angular/blob/master/modules/%40angular/router/src/router.ts),但找不到一些简单的方法来执行此操作.特别是它如何处理这些:id变量.
当然,我可以迭代Router.config,越走越深.但是后来我必须解析那些变量,正则表达式等等.必须有一种更简单的方法,因为角度路由器也必须在内部完成所有这些工作.
你有什么想法/解决方案吗?
如何在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属性?
我有一个用 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) spring ×3
angular ×2
gwt ×2
acl ×1
dependencies ×1
generics ×1
gwt-editors ×1
gwt-gin ×1
gwt-platform ×1
immutability ×1
jwt ×1
key-pair ×1
maven ×1
multi-module ×1
mysql ×1
neo4j ×1
pagination ×1
partial ×1
permissions ×1
rdbms ×1
spring-4 ×1
spring-boot ×1
spring-cloud ×1
spring-mvc ×1
sql ×1
typescript ×1
uibinder ×1