小编Seb*_*ner的帖子

带CDI的MVP; 避免循环依赖

我尝试用MVP范例构建一个Webapp.因为我希望API干净并使一切都易于测试,我尝试通过Contructor Injection注入所有可能的东西.现在我来到了一个可以看到多个Textfields的视图.当数据库中存在值时,这些文本字段会被演示者填充,因此我的演示者需要视图的引用,但是vie显然也需要引用者的引用.CDI告诉我将Presenter注入到视图中,否则由于循环依赖性而无法实现.是否可以通过setter方法避免在视图中设置演示者?代码看起来像这样:

视图:

public Class ViewImpl implements view {

private PresenterImpl presenter;
private User user;

@Inject
public ViewImpl(PresenterImpl presenter, User user) {
   super();
   this.presenter = presenter;
   this.user = user;
}

public void attach() {
   super.attach();

   presenter.fetchNames();

   showUser();
   }

public void setUser(User user) {
   this.user = user;
   }
}
Run Code Online (Sandbox Code Playgroud)

主持人:

public Class PresenterImpl implements Presenter {

private ViewImpl view;
private User user;

@Inject
public PresenterImpl(ViewImpl view, User user) {
   this.view = view;
   this.user = user;
}


public void fetchNames() {
   fetchFromDB(); …
Run Code Online (Sandbox Code Playgroud)

java cdi

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

从Eclipse格式化程序文件创建Checkstyle配置

目前,我们的团队正在使用自定义的Eclipse Formatter配置。有没有一种方法可以将生成的xml文件导入到Checkstyle中,使它们都在同一规则集上?

eclipse formatter checkstyle

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

从Scala中的地图列表中删除元素

我有一个ListMap,每个含有三个键/值对:

List(
  Map("id" -> 1, "key" -> 11, "value" -> 111), 
  Map("id" -> 2, "key" -> 22, "value" -> 222), 
  Map("id" -> 3, "key" -> 33, "value" -> 333), 
  Map("id" -> 4, "key" -> 44, "value" -> 444))
Run Code Online (Sandbox Code Playgroud)

我想将其转换为JSON,但在此之前,我需要key从每个地图中删除它的值并将value密钥重命名为title.如何在Scala中以优雅的方式完成此操作?

collections scala scala-collections

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