走过海棠暮

文章 评论 浏览 25

走过海棠暮 2024-09-26 17:14:36

我这样做的方式是 BO 期望一个 DataReader 或 DataContext 或从 DAL 返回的任何内容,而不是实际形成的对象。然后 BO 层的工作就是从返回的对象中获取并填充自身。 DAL 不会返回已完成的 BO。要记住的主要事情是,更改 BO 层中的某些内容不应导致 DAL 层出现问题,但更改 DAL 层中的某些内容可能会导致 BO 层出现问题。

执行的操作的简短示例

我通常在 BO 层中

FillData(){
   DataReader dr = DataLayer.GetData("SomePropertyForAStoreProcedure");
   If dr.Read(){
    Property1 = dr.GetValue("Property1");
    //So on and so forth
   }
}

在 DAL 中

DataReader GetData(String SPProperty){

}

The way the I do this is the BO expects a DataReader or a DataContext or whatever back from the DAL, not the actual formed object. It is then the job of the BO layer to take and fill itself from the object that came back. The DAL isn't returning back a completed BO. The main thing to remember is that changing something in the BO layer shouldn't cause issues for the DAL layer, but changing something in the DAL layer could cause issues for the BO layer.

A short example of what I typically do

In the BO layer

FillData(){
   DataReader dr = DataLayer.GetData("SomePropertyForAStoreProcedure");
   If dr.Read(){
    Property1 = dr.GetValue("Property1");
    //So on and so forth
   }
}

In the DAL

DataReader GetData(String SPProperty){

}

业务对象和数据层

走过海棠暮 2024-09-26 07:25:58

为此,您不需要(或特别需要)jQuery(它对于许多其他事情非常有用,但不是特别适合这个)。直接 JavaScript 和 DOM:

var div = document.getElementById('block-id-45');
var n = div.id.lastIndexOf('-');
var target = div.id.substring(n + 1);

实例: http://jsbin.com/osozu

如果您已经在使用 jQuery,您可以将第一行替换为:

var div = $('#block-id-45')[0];

...但是几乎没有理由这样做。

You don't need (or particularly want) jQuery for this (it's very useful for lots of other things, just not particularly for this). Straight JavaScript and DOM:

var div = document.getElementById('block-id-45');
var n = div.id.lastIndexOf('-');
var target = div.id.substring(n + 1);

Live example: http://jsbin.com/osozu

If you're already using jQuery, you can replace the first line with:

var div = $('#block-id-45')[0];

...but there's little if any reason to.

使用 jQuery 获取字符串的一部分

走过海棠暮 2024-09-25 13:20:03

由于您的函数看起来不需要返回任何值,因此您可以将每个 ID 键与调用您想要的方法的 Runnable 对象相关联。例如:

Map<Integer, Runnable> map = ...;
map.put(0, new Runnable() {
  public void run() {
    doSomeFunction();
  }
});

map.get(0).run();

如果您需要方法能够返回值,则可以使用 Callable 而不是 Runnable。您还可以创建自己的类似界面并在需要时使用它。

目前,在 Java 中,此类事情必须通过具有单个抽象方法(例如 Runnable)的类实例来完成。 Java 7 或 8(取决于他们决定如何继续)将添加 lambda 表达式和方法引用,我认为这是您真正想要的。方法引用将允许您执行类似的操作(使用 Map 就像上面一样)。

map.put(0, Foo#doSomeFunction());

编辑

您的更新表明其中一些方法需要传递参数。但是,您似乎要求两件不同的事情。在声明映射的示例中,

0 -> doSomeFunction(argument);
1 -> doSomeOtherFunction();
2 -> doStuff(arg2);

指定了参数,表明它们是声明映射时可用的值,或者是类中的字段或类似字段。无论哪种情况,您都可以在创建 Runnable 时声明它们:

 new Runnable() {
   public void run() {
     doSomeFunction(argument);
   }
 }

这里,argument 要么需要是一个字段,要么被声明为 final< /代码>。

另一方面,如果您在创建映射时没有对参数的引用,则必须创建一些所有方法调用都可以共享的一致接口。例如,适用于您的示例的最不常见的接口是声明两个参数和 void 返回的接口:

public interface CustomRunnable<T,G> {
  public void run(T arg1, G arg2);
}

那么您可以:

map.put(0, new CustomRunnable<Foo,Bar>() {
  public void run(Foo arg1, Bar arg2) {
    doSomeFunction(arg1);
  }
});
map.put(1, new CustomRunnable<Foo,Bar>() {
  public void run(Foo arg1, Bar arg2) {
    doSomeOtherFunction();
  }
});
map.put(2, new CustomRunnable<Foo,Bar>() {
  public void run(Foo arg1, Bar arg2) {
    doStuff(arg2);
  }
});

每个 CustomRunnable 仅使用参数它需要的,如果有的话。然后你可以像这样进行调用:

map.get(item.id).run(argument, arg2);

显然,这变得非常难看,但这几乎是你在这种情况下必须做的。

Since it looks like your functions don't need to return any values, you could associate each ID key with a Runnable object that calls the method you want. For example:

Map<Integer, Runnable> map = ...;
map.put(0, new Runnable() {
  public void run() {
    doSomeFunction();
  }
});

map.get(0).run();

If you need the methods to be able to return a value, you can use Callable rather than Runnable. You can also create your own similar interface and use it instead if needed.

Currently in Java this sort of thing has to be done with an instance of a class with a single abstract method such as Runnable. Java 7 or 8 (depending on how they decide to proceed) will add lambda expressions and method references, which I think is what you really want. Method references would allow you to do something like this (using a Map<Integer, Runnable> just like above).

map.put(0, Foo#doSomeFunction());

Edit:

Your update indicates that some of these methods would need to have arguments passed to them. However, you seem to be asking for two different things. In your example of declaring the mapping

0 -> doSomeFunction(argument);
1 -> doSomeOtherFunction();
2 -> doStuff(arg2);

the arguments are specified, indicating that they are either values that are available at the time you declare the mapping or they're fields in the class or some such. In either case, you'd be able to declare them when you create the Runnable:

 new Runnable() {
   public void run() {
     doSomeFunction(argument);
   }
 }

Here, argument would either need to be a field or be declared final.

If, on the other hand, you don't have references to the arguments at the time you create the mapping, you'd have to create some consistent interface that all the method calls could share. For example, the least common interface that could work for your sample would be one that declared two parameters and a void return:

public interface CustomRunnable<T,G> {
  public void run(T arg1, G arg2);
}

Then you could have:

map.put(0, new CustomRunnable<Foo,Bar>() {
  public void run(Foo arg1, Bar arg2) {
    doSomeFunction(arg1);
  }
});
map.put(1, new CustomRunnable<Foo,Bar>() {
  public void run(Foo arg1, Bar arg2) {
    doSomeOtherFunction();
  }
});
map.put(2, new CustomRunnable<Foo,Bar>() {
  public void run(Foo arg1, Bar arg2) {
    doStuff(arg2);
  }
});

Each CustomRunnable only uses the arguments that it needs, if any. Then you could do the call like this:

map.get(item.id).run(argument, arg2);

Obviously, this is getting pretty ugly but it's pretty much what you'd have to do in that case.

为给定值定义回调函数

走过海棠暮 2024-09-25 10:28:34

如果可行的话,最好激活某种结构分析来找到循环并打破僵局。

它可能会错过一些销毁时的死锁,但它也可能适用于捕获该上下文之外的死锁。

It would be better, if feasible, to activate some kind of structure analysis to find the cycle and break the deadlock.

It might miss some deadlocks on destruction, but then again it might also be applicable to catch deadlocks outside that context.

如果我不加入“破坏”线程怎么办?在发布版本中?

走过海棠暮 2024-09-25 09:05:40

在 C 和 C++ 中,单引号标识单个字符,而双引号创建字符串文字。 'a' 是单个 a 字符文字,而 "a" 是包含 'a' 和空终止符(即是一个 2 个字符的数组)。

在 C++ 中,字符文字的类型是 char,但请注意,在 C 中,字符文字的类型是 int,即 sizeof 'a'<在整数为 32 位(CHAR_BIT 为 8)的体系结构中, /code> 为 4,而 sizeof(char) 在任何地方都为 1。

In C and in C++ single quotes identify a single character, while double quotes create a string literal. 'a' is a single a character literal, while "a" is a string literal containing an 'a' and a null terminator (that is a 2 char array).

In C++ the type of a character literal is char, but note that in C, the type of a character literal is int, that is sizeof 'a' is 4 in an architecture where ints are 32bit (and CHAR_BIT is 8), while sizeof(char) is 1 everywhere.

C 或 C++ 中的单引号与双引号

走过海棠暮 2024-09-25 07:53:16

如果它是稍微复杂的 CSV 数据(例如,它嵌入了逗号),请使用 csv 标准库模块

require 'csv'
str = 'abc,def,"ghi,jlk",mno'
fields = CSV.parse_line(str)
fields.reverse!  # or do whatever manipulation
new_line = CSV.generate_line(fields) 
# => "mno,\"ghi,jlk\",def,abc\n"

If it's slightly more complicated CSV data (e.g. it has embedded commas), use the csv standard library module

require 'csv'
str = 'abc,def,"ghi,jlk",mno'
fields = CSV.parse_line(str)
fields.reverse!  # or do whatever manipulation
new_line = CSV.generate_line(fields) 
# => "mno,\"ghi,jlk\",def,abc\n"

如何使用 Ruby 删除 CSV 字符串的一部分?

走过海棠暮 2024-09-25 06:46:58

您的积分有效。

对于较小的应用程序,如果不需要所有附加功能,我会考虑在 ASP.NET 应用程序中使用 ReportViewer 控件。即使从维护的角度来看:您只需要管理一个应用程序。我的团队计划停止使用 SSRS。

我知道我们的一些姐妹团队有复杂的报告和结构,并且需要附加功能。

Your points are valid.

For a smaller app, I'd consider using a ReportViewer control in an ASP.NET app if you don't need all the bells and whistles. Even from a maintenance perspective: you only have to manage one app. My team is planning to stop using SSRS.

I know some of our sister team have complex reports and structures, and need the bells and whistles.

Sql Server Reporting Services 与通过 .NET 应用程序进行报告

走过海棠暮 2024-09-25 06:07:42

您不需要迭代事物,有一个名为 array_diff 的函数:

http://www.php.net/manual/en/function.array-diff.php

因此,创建两个逗号分隔列表的数组并使用 array_diff,得到的数组是这两个数组的差值。

在数据库中存储逗号分隔的列表不是一个好主意,因为它破坏了规范化。

you don't need to iterate over things, there's a function called array_diff:

http://www.php.net/manual/en/function.array-diff.php

So create 2 arrays of the comma separated list and use array_diff, the resulting array is the difference of these two.

Storing comma separated lists in a database isn't a good idea because it breaks normalization.

从数组中删除值数组的最佳方法是什么?

走过海棠暮 2024-09-24 20:54:59

我一直在使用几乎相同的设置,除了 vim,它是我从 Macports 获取的。几年前,我发现了 ir_black 并喜欢它。我现在将它用于所有 vim 会话、Terminal.app 和 TextMate。让它与 Leopard 一起工作,然后 Snow Leopard 就有点做作了。但情况已经有所改善。按照此处的说明操作,让 Terminal.app 在 Snow Leopard 中看起来很棒< /a>.

I've been using a nearly identical setup, except for vim, which I grab from Macports. A few years ago I found ir_black and loved it. I now use it for all vim sessions, Terminal.app, and TextMate. Getting it to work with Leopard, and then Snow Leopard was a tad hokey. But things have improved. Follow the instructions here, Making Terminal.app look great in Snow Leopard.

Mac OS X vim 颜色损坏

走过海棠暮 2024-09-24 20:08:40

Firebug 不允许您通过代码更改控制台上的行号。

Firebug does not allow you to change the line number on the console via code.

让 firebug 控制台显示不同的行号

走过海棠暮 2024-09-24 19:54:46

只需转到项目->项目属性
链接器->输入
在附加依赖项中添加 ws2_32.lib
链接器 -> 命令行在此处添加 ws2_32.lib
单击开始

simply go to project->project properties
linker->input
in additional dependencies add ws2_32.lib
linker ->command line add here ws2_32.lib
click start

winsock2.h,没有这样的文件或目录

走过海棠暮 2024-09-24 10:12:46

函数名称开头不需要 $ 符号。

这样做:

function getUserName() {
  return $this->userName;
}

Function names does not need $ sign at the beginning.

Do it like that:

function getUserName() {
  return $this->userName;
}

PHP“解析错误,需要‘T_STRING’” ” - 请帮助编写代码

走过海棠暮 2024-09-24 07:14:44

从我的脑海中浮现出来,我敢打赌这是一个路径问题。您的包含与执行脚本相关,而不是包含的包含,如果这有意义的话。

Off the top of my head, I bet this is a path issue. Your includes are relative to the executing script, not the include of the include, if that makes any sense.

PHP include 适用于 Wordpress 的 index.php 文件,而不适用于 header.php 文件?

走过海棠暮 2024-09-24 05:45:26

我认为你的推理很好,我讨厌当我在 Visual Studio 中本地化异常并且无法找到帮助时,因为编程的通用语言是英语。

更一般地说,您不应该尝试遵守所有 fxcop 规则,这很快就会成为一种负担。最好专注于规则的子集。

我不认为您可以排除特定异常中的警告,但您可以使用 SuppressMessage 属性排除检测:

[SuppressMessage("Microsoft.Globalization", 
                 "CA1303:DoNotPassLiteralsAsLocalizedParameters", 
                 Justification="Exception are not localized")]
public bool IsPageAccessible(string url, string documentId) {
  if (url == null) {
    throw new ArgumentNullException("url", @"url must not be null, use string.Empty if you don't care what the url is.");
  }

  if (documentId == null) {
    throw new ArgumentNullException("documentId", "documentId must not be null, use string.Empty if you don't care what the documentId is.");
  }
  return true;
}

另一种方法是编写 自定义 fxcop 规则 添加此行为。

I think your reasoning is good, I hate it when I have localized exception in Visual Studio and can't find help on it because the lingua franca for programming is English.

More generally, you shouldn't try to conform to every fxcop rules, this can quickly be a burden. It is better to concentrate on a subset of rules.

I don't think that you can exclude warning in a particular exception, but you can exclude detection using SuppressMessage attribute :

[SuppressMessage("Microsoft.Globalization", 
                 "CA1303:DoNotPassLiteralsAsLocalizedParameters", 
                 Justification="Exception are not localized")]
public bool IsPageAccessible(string url, string documentId) {
  if (url == null) {
    throw new ArgumentNullException("url", @"url must not be null, use string.Empty if you don't care what the url is.");
  }

  if (documentId == null) {
    throw new ArgumentNullException("documentId", "documentId must not be null, use string.Empty if you don't care what the documentId is.");
  }
  return true;
}

Another way, would be to write a custom fxcop rule to add this behavior.

从异常实例化中排除 FxCop DoNotPassLiteralsAsLocalizedParameters 违规或本地化异常消息

走过海棠暮 2024-09-24 00:06:25

日益流行的 D3 库很好地处理了附加/操作 svg 的奇怪问题。您可能需要考虑使用它,而不是这里提到的 jQuery hacks。

HTML

<svg xmlns="http://www.w3.org/2000/svg"></svg>

JavaScript

var circle = d3.select("svg").append("circle")
    .attr("r", "10")
    .attr("style", "fill:white;stroke:black;stroke-width:5");

The increasingly popular D3 library handles the oddities of appending/manipulating svg very nicely. You may want to consider using it as opposed to the jQuery hacks mentioned here.

HTML

<svg xmlns="http://www.w3.org/2000/svg"></svg>

Javascript

var circle = d3.select("svg").append("circle")
    .attr("r", "10")
    .attr("style", "fill:white;stroke:black;stroke-width:5");

jquery 的追加不适用于 svg 元素?

更多

推荐作者

愿与i

文章 0 评论 0

♡⃝ 酴醾

文章 0 评论 0

晚安先生.

文章 0 评论 0

123

文章 0 评论 0

时光清浅

文章 0 评论 0

避讳

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文