小编mar*_*ore的帖子

在MySQL Loopback Connector上执行原始查询

如何通过带有strongloop的REST API执行原始查询并公开结果?

我已经阅读了有关使用的内容hooks,dataSource.connector.query()但我找不到任何有用的例子.

mysql node.js strongloop loopbackjs

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

将业务逻辑放在实体中

我已经阅读了福勒关于" 贫血领域模型 " 的文章(链接:http://www.martinfowler.com/bliki/AnemicDomainModel.html),我同意他的观点.

我试图创建一个实体是简单POPO的应用程序,但是这样,我有一个胖服务层,而将一些逻辑放到实体中将是最简单的解决方案.

所以我会有这样的架构:

^
| Twig
| Controller | API
| Service
| Model
| Entity
Run Code Online (Sandbox Code Playgroud)

哪里:

实体:将是简单的POPO,只是一袋二传手和吸气剂

模型:将是用业务逻辑装饰的实体对象

服务:包含涉及多个实体的所有业务逻辑(这里我也会放置验证任务),并且像转换器实体一样 - >模型

控制器| API:只匹配Request with Service,ParamConvert并检查autorization

Twig:表示层

我的问题是如何将实体层隐藏到控制器并且仅适用于模型.为了用业务逻辑来装饰我的实体,我想构建一个使用存储库并装饰结果的服务(我找不到另一种方法来实现它).

所以,一个愚蠢的例子:

namespace ...\Entity\Article;
class Article {
    private $id;
    private $description;

    // getter and setter
}


namespace ...\Model\Article;
class Article {
    private $article; // all methods will be exposed in some way
    private $storeService; // all required services will be injected …
Run Code Online (Sandbox Code Playgroud)

php entity-framework software-design symfony doctrine-orm

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

所有组合都没有重复,具有特定的基数

我有一个数组:

[a, b, c, d, e, f, ... , z]
Run Code Online (Sandbox Code Playgroud)

并且我将生成所有可能的子阵列的集合,不重复,其基数在X和Y之间.

我们假设php:

$array = array(1, 2, 3, 4, 5, 6, 7, 8);

$results = myFunction($array, 3, 5);
Run Code Online (Sandbox Code Playgroud)

我的函数应该返回如下内容:

array( 
    array(1, 2, 3),
    array(1, 2, 4),
    ...
    array(4, 5, 6, 7, 8),
);
Run Code Online (Sandbox Code Playgroud)

我的尝试是以二进制计数,从0到2 ^ n(其中n是集合的基数),如果数字1s在X和Y之间,则将由1s元素组成的数组添加到结果集中.

例如.

8  = 0000 0111 => add (6,7,8) to result
9  = 0000 1000 => no 
10 = 0000 1001 => no
...
Run Code Online (Sandbox Code Playgroud)

但它非常难看!有更好的算法吗?

我正在使用PHP,但随意使用你喜欢的任何语言.

php algorithm combinations

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

TableLayout中具有相同宽度的列,*以编程方式*

我在SO上读到,为了获得一个tablelayout,其中每列具有相同的宽度,您可以设置android:width="0dp"android:weight="1"作为布局参数,它可以工作.我会得到相同的结果,但编程,所以我尝试了这一块代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_score, container, false);

    TableRow row = (TableRow)rootView.findViewById(R.id.playerRow);
    for (Player p : game.getPlayers()) {
        TextView t = new TextView(rootView.getContext());
        t.setText(p.getName());
        row.addView(t, new TableLayout.LayoutParams(0, TableLayout.LayoutParams.WRAP_CONTENT, 1f));
        // with the previuos line of code, nothing is showed
        // instead this work: row.addView(t) , but each column doesn't take the maximum width (as I would)

    }

    return rootView;
}
Run Code Online (Sandbox Code Playgroud)

但正如评论中所解释的那样,它不能按预期工作.我无法得到我所缺少的东西.

android android-layout

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